0

HTML フォームを使用してサーバーにファイルをアップロードし、サーバーで TXT ファイルを作成してエラー ログを書き込みますが、このプロセスはローカル システムと他のサーバーでは正常に実行されますが、この操作が必要な 1 つのサーバーでは実行されません。

エラーメッセージ:

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);
}
4

2 に答える 2

0

thous テスト ケースを実行すると、どのようなエラー メッセージが表示されますか?

if(!is_dir('taskfinished'))
{
   die("1: dir taskfinished dosn't exists\n");
}

if(!is_writable('taskfinished'))
{
   die("2: dir taskfinished isn't writeable\n");
}

$file_resource = fopen('taskfinished/test.txt', 'w');
if(!$file_resource)
{
   die("3: failed to open file\n");
}

if(!fwrite($file_resource, 'test'))
{
   fclose($file_resource);
   die("4: Failed to write to file\n");
}

fclose($file_resource);
die("All test passed\n");

1 の場合はフォルダを作成する必要がありますmkdir taskfinished
2 フォルダの所有者または権限を変更する必要がありますchown apache:apache taskfinished(CHangeOWNer をユーザー apache およびグループ apache に変更) またはchmod o+w(所有者のモードを変更して書き込みを追加) 3 または 4

于 2013-07-30T12:27:21.963 に答える