gpt4 book ai didi

php - getimagesize() 函数不适用于 linux

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:57 24 4
gpt4 key购买 nike

我有这个功能

public static function upload($path_folder, $input_file_name) {

$photo_file = $_FILES[$input_file_name]; // FILE NAME
$photo_name = $photo_file['name']; // PHOTO NAME
$photo_tmp_name = $photo_file['tmp_name']; // TMP NAME
$photo_extension = pathinfo($photo_name, PATHINFO_EXTENSION); // EXTENSION
// soon GIFs

$rand_num = random_int(1, 3);
switch ($rand_num) {
case 1:
$hash = mb_strtoupper(Hash::create(), 'UTF-8');
break;
case 2:
$hash = mb_strtolower(Hash::create(), 'UTF-8');
break;
case 3:
$hash = str_shuffle(Hash::create());
break;
default:
$hash = Hash::create();
break;
}

$photo_with_extension = $hash . '.' . $photo_extension; // NEW FILE NAME
$factory_destination = 'photos/factory/' . $photo_with_extension; // FACTORY

if(move_uploaded_file($photo_tmp_name, $factory_destination)) {
if(file_exists($factory_destination)) {
if(
($photo_extension === 'jpg') ||
($photo_extension === 'jpeg') ||
($photo_extension === 'JPG') ||
($photo_extension === 'JPEG') ||
($photo_extension === 'png') ||
($photo_extension === 'PNG')
) {

if(
($photo_extension === 'jpg') ||
($photo_extension === 'jpeg') ||
($photo_extension === 'JPG') ||
($photo_extension === 'JPEG')
) {
if(imagecreatefromjpeg($factory_destination)) { // JPEG
$photo_create = imagecreatefromjpeg($factory_destination);
}
}

if(
($photo_extension === 'png') ||
($photo_extension === 'PNG')
) {
if(imagecreatefrompng($factory_destination)) { // PNG
$photo_create = imagecreatefrompng($factory_destination);
}
}

if(getimagesize($photo_tmp_name)) {

list($photo_width, $photo_height) = getimagesize($photo_tmp_name); // WIDTH & HEIGHT
$photo_new_width = 300; // NEW WIDTH
$photo_new_height = 300;
//$photo_new_height = ($photo_height / $photo_width) * $photo_new_width; // NEW HEIGHT
$true_color = imagecreatetruecolor($photo_new_width, $photo_new_height); // TRUE COLOR

if(imagecopyresampled($true_color, $photo_create, 0, 0, 0, 0, $photo_new_width, $photo_new_height, $photo_width, $photo_height)) {


$photo_copy = imagecopyresampled($true_color, $photo_create, 0, 0, 0, 0, $photo_new_width, $photo_new_height, $photo_width, $photo_height); // COPY
$mime = mime_content_type($factory_destination);

if(($mime === 'image/jpeg') || ($mime === 'image/png')) {

switch ($path_folder) {
case 1:
$folder = 'profile';
break;
case 2:
$folder = 'identities';
break;

default:
$folder = 'errors';
break;
}

$new_destination = 'photos/' . $folder . '/';
//$image = imagecreatefromstring(file_get_contents($photo_tmp_name));
$exif = exif_read_data($factory_destination);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$true_color = imagerotate($true_color,90,0);
break;
case 3:
$true_color = imagerotate($true_color,180,0);
break;
case 6:
$true_color = imagerotate($true_color,-90,0);
break;
}
}
if(imagejpeg($true_color, $new_destination . $photo_with_extension, 75)) { // DESIGNATED PATHS
imagedestroy($true_color); // return

if(unlink($factory_destination)) {
return $photo_with_extension; // AUTO UPDATE ADMIN THAT THERE IS A PROBLEM
} else { return 'unlink last'; }
} else { return 'imagejpeg'; }
} else { return 'mime'; }
/*move*/
} else { return 'resampled'; }
} else { return 'get image:' . $photo_tmp_name; }
} else { return 'wrong ext'; }
} else { return 'default2.png'; }
} else { return 'move'; }
return empty($photo_with_extension) ? '' : 'false';
}

该函数一直运行到 move_uploaded_file() 之后什么都没有发生。

这是在生产、启用 GD 和兼容的 Linux 服务器上。您认为我的代码哪里出错了?不过,这在我的本地主机上工作得很好。

准确地说,imagejpeg() 是不起作用的那个

新信息;

问题似乎发生在 getimagesize($photo_tmp_name) 上,它返回 false

较新的信息:

getimagesize() 上给出的 tmp_name 在我回显时是正确的,但它返回 false。

最佳答案

如果在 move_uploaded_file() 函数之后,应该销毁 tmp_file,您可以用已经移动的文件替换 tmp_file,因为php 会执行阻塞的进程,所以这样做是安全的!

关于php - getimagesize() 函数不适用于 linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38733051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com