【发布时间】:2013-07-31 13:23:24
【问题描述】:
我正在使用 HTML 表单将文件上传到服务器并在服务器中创建一个 TXT 文件以写入错误日志,但此过程在我的本地系统和我的其他服务器中运行良好,但在此操作必须工作的一个服务器中运行良好。
错误信息:
Warning: move_uploaded_file(taskfinished/512557562_348011_RAND_488.png): failed to open stream: Permission denied in /var/www/smart_1/JSON/taskimageupload.php on line 70
Warning: move_uploaded_file(): Unable to move '/tmp/phpz3HWEJ' to 'taskfinished/512557562_348011_RAND_488.png' in /var/www/smart_1/JSON/taskimageupload.php on line 70
Warning: fopen(errorlog/07.30.13.txt): failed to open stream: Permission denied in /var/www/smart_1/JSON/errorlog.php on line 30
Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/smart_1/JSON/errorlog.php on line 35
Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/smart_1/JSON/errorlog.php on line 37
我关闭了安全模式,但问题还是一样..
如何更改服务器中的用户权限。?
我的 PHP 代码:
$finenamedynamic = $CompanyId."_".$ShibNo."_RAND_".rand(100,600);
//$finenamedynamic = date("Y-m-d-H_i_s")."_RAND_".rand(100,600);
//New file name with EXTENSION
$newfilename=$finenamedynamic.".".$extension;
// Upload file
$uploadedimage = $targetfilename . $newfilename;
//Move file to the new file path
if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadedimage)){
//Error Log
$message = "Error uploading file - check destination is writeable ". $uploadedimage;
ErrorsAreAwesome('70','taskimageupload.php','Create Directory',$message);
}
function ErrorsAreAwesome($line=null,$filename=null,$function=null,$message=null){
//Create Error file for the day
$myFile = "errorlog/".date("m.d.y").".txt";
$error_time = date("Y-m-d H:i:s");
//Construct Error
$file_write = "[".$error_time."]-->[Line:".$line."]-->[File:".$filename."]-->[Fun:".$function."]-->[Msg:".$message."]";
//if file exist appen in the file else create new file and write
if (file_exists($myFile)) {
$fh = fopen($myFile, 'a');
} else {
$fh = fopen($myFile, 'w');
}
//write in file \r\n support for this OS or \n alone work
fwrite($fh, "\r\n".$file_write."\n");
//close file after writing
fclose($fh);
}
【问题讨论】:
-
向我们展示您使用的代码。对于 linux 服务器,您可以使用 chmod 更改权限。
-
这不是一个许可。问题是您确定文件夹存在或路径正确。因为有时您必须提供完整路径,例如 /var/www/smart_1/folder
-
是的,文件夹和路径存在,这就是为什么它在我的其他服务器以及我的本地服务器上都能正常工作的原因。
-
我现在已经添加了我的代码.. @Aris
标签: php linux file-upload upload hosting