-2
    $file_extension= explode('.', $file_name); 
    $file_extn= strtolower(end($file_extension));  
    $old_file_path = $user_data['profile_pic'];

      function change_profile_image($user_id, $file_temp, $file_extn, $old_file_path){
            $file_path = 'core/images/profile/'.  substr(md5(time()), 0, 20) . '.' . $file_extn;
            move_uploaded_file($file_temp, $file_path);
            if(file_exists($old_file_path) === true){unlink($old_file_path);}
            mysql_query("UPDATE `users` SET `profile_pic` = '". mysql_real_escape_string($file_path) ."' WHERE `user_id` = " . (int)$user_id);

            if($file_extn == 'png'){
            list($width, $height) = getimagesize($old_file_path);
            $new_width = $width;
            $new_height = $height;
            $image_p = imagecreatetruecolor($new_width, $new_height);
            $image = imagecreatefrompng($old_file_path);

            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            imagejpeg($image_p, $file_path);
if(file_exists($old_file_path) === true){unlink($old_file_path);}           
mysql_query("UPDATE `users` SET `profile_pic` = '". mysql_real_escape_string($file_path) ."' WHERE `user_id` = " . (int)$user_id);
            }

            if($file_extn == 'jpg' || $file_extn == 'jpeg'){
            list($width, $height) = getimagesize($file_path);
            $new_width = $width;
            $new_height = $height;
            $image_p = imagecreatetruecolor($new_width, $new_height);
            $image = imagecreatefromjpeg($file_path);

            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            imagejpeg($image_p, $file_path);
if(file_exists($old_file_path) === true){unlink($old_file_path);}           
mysql_query("UPDATE `users` SET `profile_pic` = '". mysql_real_escape_string($file_path) ."' WHERE `user_id` = " . (int)$user_id);
            }
        }

图片正在上传,但问题是上传后没有转换图片。问题是什么?我相信 if 语句不起作用。

4

1 回答 1

0
...
move_uploaded_file($file_temp, $file_path);
if(file_exists($old_file_path) === true){unlink($old_file_path);}
...
if($file_extn == 'png'){
        list($width, $height) = getimagesize($old_file_path);
...

我相信,由于您$old_file_path在使用它之前删除getimagesize($old_file_path)它失败,所以imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);没有什么可做的。

尝试在 . 之后评论第一个文件删除move_uploaded_file。很确定是这个问题...

于 2013-02-17T20:31:33.500 回答