簡體   English   中英

主機服務器中的文件上載問題

[英]File upload issue in host server

當嘗試上傳圖像文件時,托管服務器有時會發出警告。 如果我嘗試在后續嘗試中上傳相同的文件,則會上傳圖像。

警告:

Warning (2): move_uploaded_file(files/photos/3.jpg) [http://php.net/function.move-uploaded-file]: failed to open stream: Permission denied [APP/controllers/components/file_upload.php, line 55]
Warning (2): move_uploaded_file() [http://php.net/function.move-uploaded-file]: Unable to move '/tmp/phpUutr9Z' to 'files/photos/3.jpg' [APP/controllers/components/file_upload.php, line 55]

上傳文件

if ( is_uploaded_file($file_temp) ) {
    if (move_uploaded_file($file_temp, $destination . $filename . '.' . $extension)) {
    $error = "SUCCESS";
    return $error;
    } else {
    $error = "ERROR";
    return $error;
    }
}

這里當警告到來時,其他部分的'ERROR'也會返回警告......

我怎么糾正它?

它在本地服務器上工作得很好......

您的腳本可能沒有寫入目標目錄的權限。

APP/controllers/components/files/photos/3.jpg在哪里可以保存上傳內容? 如果是這樣那么它的權限問題。

或者你的意思是: WEB_ROOT/files/photos/3.jpg如果是這樣你也需要改變你的代碼:

if ( is_uploaded_file($file_temp) ) {
    if (move_uploaded_file($file_temp, '/'.$destination.$filename.'.'.$extension)) {
    $error = "SUCCESS";
    return $error;
    } else {
    $error = "ERROR";
    return $error;
    }
}

注意正斜杠'/'.$destination

檢查目錄和文件上的CHMOD 通常PHP像root一樣運行,但你仍然可以禁止它使用CHMOD進行訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM