2010-06-01 141 views
1

使用此上傳腳本,它在一週前運行良好,但是當我今天檢查它時,它失敗。我已經檢查過該文件夾的編輯特權,它被設置爲777,所以不要認爲這是問題。任何人都知道問題是什麼?PHP上傳腳本

這是錯誤

Warning: move_uploaded_file() [function.move-uploaded-file]: 
Unable to access replays/1275389246.ruse in 
/usr/home/web/wno159003/systemio.net/ruse.systemio.net/scripts/upload.php on line 95 

我的劇本是

<?php 

    require($_SERVER['DOCUMENT_ROOT'].'/xxxx/xxxx'); 
    $connection = @mysql_connect($db_host, $db_user, $db_password) or die("error connecting"); 
    mysql_select_db($db_name, $connection); 

    $name = basename($_FILES['uploaded']['name']); 
    $comment = $_POST["comment"]; 
    $len = strlen($comment); 
    $username = $_POST["username"]; 
    $typekamp = $_POST["typekamp"]; 
    $date = time(); 


    $target = "replays/"; 
    $target .= basename($_FILES['uploaded']['name']); 
    $maxsize = 20971520; // 20mb Maximum size of the uploaded file in bytes 

// File extension control 
// Whilelisting takes preference over blacklisting, so if there is anything in the whilelist, the blacklist _will_ be ignored 
// Fill either array as you see fit - eg. Array("zip", "exe", "php") 
$fileextensionwhitelist = Array("ruse"); // Whilelist (allow only) 
$fileextensionblacklist = Array("zip", "exe", "php", "asp", "txt"); // Blacklist (deny) 
$ok = 1; 

if ($_FILES['uploaded']['error'] == 4) 

{ 
    echo "<html><head><title>php</title></head>"; 
    echo '<body bgcolor="#413839" text="#ffffff"> 
    <p><B>info</b></p>'; 
    die("No file was uploaded"); 
} 

if ($_FILES['uploaded']['error'] !== 0) 
{ 
    echo "<html><head><title>php</title></head>"; 
    echo '<body bgcolor="#413839" text="#ffffff"> 
    <p><B>info</b></p>'; 
    die("An unexpected upload error has occured."); 
} 

// This is our size condition 
if ($_FILES['uploaded']['size'] > $maxsize) 
{ 
    echo "<html><head><title>php</title></head>"; 
    echo '<body bgcolor="#413839" text="#ffffff"> 
    <p><B>info</b></p>'; 
    echo "Your file is too large.<br />\n"; 
    $ok = 0; 
} 

// This is our limit file type condition 
if ((!empty($fileextensionwhitelist) && !in_array(substr(strrchr($_FILES['uploaded']['name'], "."), 1), $fileextensionwhitelist)) || (empty($fileextensionwhitelist) && !empty($fileextensionblacklist) && in_array(substr(strrchr($_FILES['uploaded']['name'], "."), 1), $fileextensionblacklist))) 
{ 
    echo "<html><head><title>php</title></head>"; 
    echo '<body bgcolor="#413839" text="#ffffff"> 
    <p><B>info</b></p>'; 
    echo "This type of file has been disallowed.<br />\n"; 
    $ok = 0; 
} 

// Here we check that $ok was not set to 0 by an error 
if ($ok == 0) 
{ 
    echo "<html><head><title>php</title></head>"; 
    echo '<body bgcolor="#413839" text="#ffffff"> 
    <p><B>info</b></p>'; 
    echo "Sorry, your file was not uploaded. Refer to the errors above."; 
} 

// If everything is ok we try to upload it 
else 
{ 
    if($len > 0) 
    {  
     $target = "replays/".time().'.'."ruse"; 
     $name = time().'.'."ruse"; 
     $query = "INSERT INTO RR_upload(ID, filename, username, comment, typekamp, date) VALUES (NULL, '$name', '$username','$comment', '$typekamp' ,'$date')"; 

     if (file_exists($target)) 
     { 
     $target .= "_".time().'.'."ruse"; 
     echo "<html><head><title>php</title></head>"; 
     echo '<body bgcolor="#413839" text="#ffffff"> 
     <p><B>info</b></p>'; 
     echo "File already exists, will be uploaded as ".$target; 
     } 

     mysql_query($query, $connection) or die (mysql_error()); 

     echo "<html><head><title>php</title></head>"; 
     echo '<body bgcolor="#413839" text="#ffffff"> 
     <p><B>info</b></p>'; 
     echo (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 

     ? "The file ".basename($_FILES['uploaded']['name'])." has been uploaded. \n" 
     : "Sorry, there was a problem uploading your file. <br>"; 
     echo "<br>Variable filename: ".$name; 
     echo "<br>Variable name: ".$username; 
     echo "<br>Variables comment: ".$comment; 
     echo "<br>Variables date: ".$date; 
     echo "<br>Var typekamp; ".$typekamp; 
     echo "<br>Var target; ".$target; 
     } 
    else 
    { 
     echo "<html><head><title>php</title></head>"; 
     echo '<body bgcolor="#413839" text="#ffffff"> 
     <p><B>info</b></p>'; 
     echo"you have to put in comment/description"; 
    } 

} 
?> 
+0

誰承載它?你完全控制了環境嗎?或者它是一個可以禁用此功能的網絡託管公司? – anddoutoi 2010-06-01 11:26:36

+0

其在webhotel上,所以我沒有完全控制服務器設置,但我做了測試腳本上傳小圖像文件在同一臺服務器上,我沒有讓他們工作得很好。 – Darkmage 2010-06-01 11:36:49

回答

1

假設「重播」目錄中的文檔根目錄,確實如果更換該行警告仍然存在:

$target = "replays/"; 

這個:

$target = $_SERVER['DOCUMENT_ROOT']."replays/"; 

+0

你讓我的一天:)添加$ _SERVER ['DOCUMENT_ROOT']。「/ playback /」;並且一切都很好 – Darkmage 2010-06-01 12:22:01

+1

很高興提供幫助,這也突出了我們必須注意$ _SERVER ['DOCUMENT_ROOT']環境變量中尾隨斜線的存在 – 2010-06-01 12:41:20