怎么解决getimagesize空?

时间:2015-07-21 16:46:04

标签: php image image-resizing

我在调整图像大小时遇到​​问题是我的代码 getimagesize():filename不能为空

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);
                }
            }
        }

如何解决问题,因为我知道一切都是正确的,所以问题出在哪里..

1 个答案:

答案 0 :(得分:0)

在你的css中,外部div必须有position: relative作为属性,div中的导航栏本身必须有position: absolute作为其属性。