亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php訪問嵌套函數中的foreach變量

php訪問嵌套函數中的foreach變量

PHP
郎朗坤 2022-10-28 16:29:12
function processImages($images){$uploadfiles = array();// make sure images array does not contain more than 3 imagesif (count($images) <= 3) {    foreach ($images as $image) {        $uploadfile = "NULL";        if ($image['size'] != 0) {            //file process            function doFileCheck($file, $image)            {                $imginfo_array = getimagesize($file);                /*getimagesize() only works with imagesif getimagesize() fails it will returnfalse you can use var_dump() to see insidethe array.echo var_dump($imginfo_array)  */                if ($imginfo_array !== false) {                    $uploaddir = './uploads/';                    $uploadfile = $uploaddir . basename($image['name']);                    if (file_exists($uploadfile)) {                        echo "<h3>That filename already exists - try again!</h3>";                    } else {                        if (move_uploaded_file($image['tmp_name'], $uploadfile)) {                            echo "<h3>File seems valid, and was successfully uploaded</h3>";                        } else {                            echo "INVALID! Possible file upload attack!\n";                        }                    }                    return $uploadfile;                }            }我有這個文件處理函數,問題是我得到一個異常,說只有變量應該通過引用傳遞。在第一種情況下,它會在 switch 語句中引發該異常,因為我正在嘗試上傳 jpeg 圖像,但我正在調試它并且找不到問題。我將一個數組傳遞給包含表單中每個文件(總共 3 個)的函數,然后遍歷文件以處理每個文件
查看完整描述

1 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

閱讀有關array_push()的更多信息。

您正在傳遞 adoFileCheck($file, $image)而不是$array_of_varsand $new_element_in_array_of_vars。

BTW$array_of_vars[] = $new_element_in_array_of_vars;的工作速度比array_push($array_of_vars,$new_element_in_array_of_vars);.


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號