2015-07-21 58 views
0

我有一個問題,而在此調整圖像大小,是我的代碼,它說 和getimagesize():文件名不能爲空如何解決getimagesize空?

function change_profile_image($user_id, $file_temp, $file_extn) { 
$username = $_SESSION['username']; 
$file_path = 'style/images/users/'.sha1($username).'/'. substr(sha1(time()), 0, 100). '.' . $file_extn; 
move_uploaded_file($file_temp, $file_path); 
$secure = mysql_real_escape_string($file_path); 
$src = imagecreatefromjpeg($secure); 
$size = getimagesize($file_path); 
$width = $size[0]; 
$height = $size[1]; 
$new_width = 700; 
$new_height = ($height /$width) * $new_width; 

$temp = imagecreatetruecolor($new_width, $new_height); 
imagecopyresampled($temp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 
$imgs = imagejpeg($temp,$file_path,100); 
$user_photo_id = $_SESSION['user_id']; 
mysql_query("INSERT INTO photos (photo_id,user_id,profile) VALUES (NULL,'$user_photo_id','$imgs')"); 

}

以上是我的圖片調整的代碼,這裏是我的圖片上傳代碼..

if(isset($_FILES['profile']) === true){ 
      if(empty($_FILES['profile']['name']) === true){ 
       echo 'Please choose a file'; 
      }else{ 

       $allowed = array('jpg','jpeg','png'); 
       $file_name = $_FILES['profile']['name']; 
       $file_extn = strtolower(end(explode('.', $file_name))); 
       $file_temp = $_FILES['profile']['tmp_name']; 

       if(in_array($file_extn, $allowed) === true){ 

        $names = change_profile_image($_SESSION['user_id'],      $file_temp, $file_extn); 
        $image_size = getimagesize($names); 

        echo $image_size; 
        exit(); 
        //echo "<img src='".$user_data['profile']."'"; 

        header('Location: profile.php'); 
       }else{ 
        alert('incorrect file format'); 
        //echo implode(', ', $allowed); 
       } 
      } 
     } 

如何解決這個問題按照我知道的一切是正確的那麼問題出在哪裏..

+0

你有任何HTML/CSS已經創建?你可以發佈這些嗎? – wkcamp

回答

0

在您的CSS中,外部div必須具有position: relative作爲屬性,並且div內的導航欄本身必須具有position: absolute作爲其屬性。