[英]How to use getImagesize() for an uploaded file before it gets saved into the server?
鑒於getImagesize()需要一個字符串並且$_FILES['myfile']
是一個數組,我試圖進入臨時文件夾並將文件上傳到那里以獲取圖像大小,但是我確實得到了一個錯誤。
警告:getimagesize(/home/everymorning/public_html/tmp/phpNFuAMD/images.jpeg):無法打開流:第48行的/home/everymorning/public_html/demo1.php中沒有此類文件或目錄
$string = $_SERVER['DOCUMENT_ROOT'].$_FILES['myfile']['tmp_name'].'/'.$_FILES['myfile']['name'];
echo getimagesize($string);
而且, 如果我嘗試直接使用臨時路徑 ,仍然會收到錯誤消息:
getimagesize($_FILES['myfile']['tmp_name']);
注意:第47行的/home/everymorning/public_html/demo1.php中的數組到字符串的轉換
我認為getimagesize($fileName)
具有以下內容-
Array ( [0] => 667
[1] => 184
[2] => 3
[3] => width="667" height="184"
[bits] => 8
[mime] => image/png );
您正在嘗試將Array to string conversion
的array-error錯誤回顯Array to string conversion
。 實際的echo無法打印數組,而print_r
和var_dump
是可以打印數組的信息。
要計算圖像的大小,您可以簡單地通過將高度寬度與用於表示像素的位相乘來進行計算,以下算術表達式可以為您提供圖像的大小(以位為單位)。
$imageInfo = getimagesize($fileName);
$size = $imageInfo[0] * $imageInfo[1] * $imageInfo['bits'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.