有人可以幫助我,幾乎所有的可能頭髮都已經走了。試圖將大圖片上傳到網站時遇到問題。我已經解決了這個問題,一切似乎都正常。我用10Mb + JPEG文件測試了我的腳本,並且看起來都很完美。但是,我剛剛嘗試從某個電話(4.9Mb)上載JPEG,並且出現500錯誤。看看PS中的圖片,尺寸爲72dpi時寬1054px,高1874px。任何人都可以幫助我,爲什麼這是一個問題,我怎麼解決它?如果我把圖片縮小(700px寬),它會上傳嗎?大尺寸PHP上傳圖片
有沒有人有同樣的問題?下面是我的代碼,它旋轉圖像(因爲手機上傳的一些內容一旦上傳),然後調整大文件的大小以便存儲。我測試過的所有照片似乎都能正常工作......除了這張照片外,這張照片很蠢!有人請幫忙!
$file_name = $_FILES['newPicture']['tmp_name'];
correctImageOrientation($file_name);
AdjustPicSize($file_name);
function correctImageOrientation($file_name) {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($file_name);
if($exif && isset($exif['Orientation']) || !isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
$img = imagecreatefromjpeg($file_name);
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
if ($deg) {
$img = imagerotate($img, $deg, 0);
}
// then rewrite the rotated image back to the disk as $filename
imagejpeg($img, $file_name, 95);
} // if there is some rotation necessary
} // if have the exif orientation info
} // if function exists
}
function AdjustPicSize($file_name)
{
$maxDim = 800;
list($width, $height, $type, $attr) = getimagesize($file_name);
if ($width > $maxDim || $height > $maxDim) {
$target_filename = $file_name;
$ratio = $width/$height;
if($ratio > 1) {
$new_width = $maxDim;
$new_height = $maxDim/$ratio;
} else {
$new_width = $maxDim*$ratio;
$new_height = $maxDim;
}
$src = imagecreatefromstring(file_get_contents($file_name));
$dst = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($dst, $target_filename); // adjust format as needed
}
}
請溫和一點,我對這一切都有點新鮮感!
比500錯誤更詳細的信息將有助於診斷。你可以檢查你的PHP日誌文件,看看實際的錯誤是什麼? – Bert