简体   繁体   English

主机服务器中的文件上载问题

[英]File upload issue in host server

When try to upload a image file, hosting server makes warning sometimes. 当尝试上传图像文件时,托管服务器有时会发出警告。 If i try uploading the same file in succeeding tries the image will be uploaded. 如果我尝试在后续尝试中上传相同的文件,则会上传图像。

Warning: 警告:

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]

File Upload 上传文件

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

Here when warning comes 'ERROR' in else portion is also returned with warning... 这里当警告到来时,其他部分的'ERROR'也会返回警告......

How I can correct it ? 我怎么纠正它?

It is working nice in local server... 它在本地服务器上工作得很好......

您的脚本可能没有写入目标目录的权限。

So is APP/controllers/components/files/photos/3.jpg where you want to save your uploads? APP/controllers/components/files/photos/3.jpg在哪里可以保存上传内容? If so then its a permissions problem. 如果是这样那么它的权限问题。

Or do you mean: WEB_ROOT/files/photos/3.jpg if so you need to change your code too: 或者你的意思是: 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;
    }
}

notice the forward slash '/'.$destination 注意正斜杠'/'.$destination

Check the CHMOD on the directory and on the file. 检查目录和文件上的CHMOD Usually PHP is ran like root , but you can still forbid it's access with CHMOD. 通常PHP像root一样运行,但你仍然可以禁止它使用CHMOD进行访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM