簡體   English   中英

如何解決getimagesize為空?

[英]how to solve getimagesize empty?

調整圖片大小時出現問題,這是我的代碼,上面寫着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);
                }
            }
        }

我知道如何解決問題,所以一切都在正確的地方。.

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM