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

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

move_uploaded_file 保存在錯誤的目的地

move_uploaded_file 保存在錯誤的目的地

PHP
江戶川亂折騰 2023-06-24 18:21:33
我正在嘗試使這段代碼正常工作:if ($this->request->is(['patch', 'post', 'put'])){                $nameImg = $this->request->getData()['imagem']['name'];        $imgTmp = $this->request->getData()['imagem']['tmp_name'];        $destination = "files\user\\".$user_id."\\".$nameImg;                if(move_uploaded_file($imgTmp,WWW_ROOT . $destination)){            $this->Flash->success(__('Success!'));                        }        }但每次我嘗試運行它時,圖像都會保存在我的 webroot 目錄中,而不是我指定的 $destination 路徑上,所有目錄都設置為 777 并且 move_uploaded_file 返回 true,我可以做些什么來使其保存在指定路徑上?這是$this->request->getData();調試輸出:[    'imagem' => [        'tmp_name' => '/tmp/phpTrcN6K',        'error' => (int) 0,        'name' => 'icone1.png',        'type' => 'image/png',        'size' => (int) 15778    ]]
查看完整描述

1 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

嘗試在路徑中使用目錄分隔符(DS):


if ($this->request->is(['patch', 'post', 'put'])){

    $nameImg = $this->request->getData('imagem.name');

    $imgTmp = $this->request->getData('imagem.tmp_name');


    $destination = WWW_ROOT . 'files' . DS . 'user' . DS . $user_id . DS . $nameImg;

    

    if(move_uploaded_file($imgTmp, $destination)){

        $this->Flash->success(__('Success!'));

        }

    }


查看完整回答
反對 回復 2023-06-24
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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