我正在尝试设置一个上传站点,但无法获得上传文件的脚本。(上传文件夹的所有权限都设置为777。)我继续收到这些错误:
Warning: move_uploaded_file(/var/chroot/home/content/44/9976344/html/tech/filemanager/uploads/Ace_planning_instructions.docx) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/44/9976344/html/tech/tech/js/upload.php on line 72
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpo89pGR' to '/var/chroot/home/content/44/9976344/html/tech/filemanager/uploads/Ace_planning_instructions.docx' in /home/content/44/9976344/html/tech/tech/js/upload.php on line 72
Error! Most likely upload directory doesn't have writable permissions or you didn't set it up correctly.
我可以做些什么来修复或解决这些错误?
这是我的代码:
<?php
require_once("../includes/dbconnect.php"); //Load the settings
require_once("../includes/functions.php"); //Load the functions
// Work-around for setting up a session because Flash Player doesn't send the cookies
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
session_start();
$upload_dir = (!empty($_POST["upload_dir"]))?strip_tags(str_replace("'","`",$_POST["upload_dir"])):getUploadDir($_SESSION["idUser"]);
if($demo){
echo "Uploads disabled in demo!";
} else {
$q="SELECT id,parentID FROM folders WHERE name='".$upload_dir."'";
$res=mysql_query($q);
$rrr=mysql_fetch_assoc($res);
$folderID=$rrr["id"];
if($rrr["parentID"]!=0){
$q2="SELECT name FROM folders WHERE id='".$rrr["parentID"]."'";
$res2=mysql_query($q2);
$rrr2=mysql_fetch_assoc($res2);
$tmpStr=$rrr2["name"]."/";
} else { $tmpStr = ""; }
$uploadfile = $_SERVER['DOCUMENT_ROOT'].$script_dir.$tmpStr.$upload_dir."/".(str_replace(" ","_",$_FILES['Filedata']['name']));
$FileNametmp = $_FILES['Filedata']['name'];
$fileNamePartstmp = explode(".", $FileNametmp);
$counter2 = count($fileNamePartstmp)-1;
$fileExtensiontmp = strtolower($fileNamePartstmp[$counter2]); // Estension (part behind last dot)
$title=$FileNametmp;
$fsize = filesize($_FILES['Filedata']['tmp_name']);
$fileEXT = strtoupper($fileExtensiontmp);
//get limits for current user.
$sSQL = "SELECT id,username,filesize,quota,extensions FROM users WHERE id='".$_REQUEST["user"]."'";
$result = mysql_query($sSQL) or die("err: " . mysql_error().$sSQL);
if($row = mysql_fetch_assoc($result)){
$max_filesize = $row["filesize"];
$extensionsArr = explode(",",$row["extensions"]);
$sql2="SELECT SUM(size) userQuota FROM files WHERE userID='".$_REQUEST["user"]."'";
$result2=mysql_query($sql2) or die("error getting user files sizes");
$rr=mysql_fetch_assoc($result2);
$max_quota = $row["quota"];
$current_quota = $rr["userQuota"];
}
$upload=false;
//validations
if($current_quota<($max_quota * 1024 * 1024)){
if($current_quota + $fsize <=($max_quota * 1024 * 1024)){
if($fsize<=($max_filesize * 1024 * 1024)){
for($i=0;$i<count($extensionsArr);$i++){
if($extensionsArr[$i]==$fileEXT){
$upload=true;
}
}
if($upload){
//everything ok, upload file.
//if($fileEXT=="EXE" || $fileEXT=="COM" || $fileEXT=="BAT" || $fileEXT=="HTM" || $fileEXT=="HTML" || $fileEXT=="PHP" || $fileEXT=="JS"){
//addLog($_SESSION["idUser"],"forbidden file upload $title ");
//$msg = "Such files are forbidden in demo version.";
//} else {
//$filePath=uploadFile($_FILES['file'], $upload_dir.$title."_".$_SESSION["idUser"].".".$fileExtensiontmp);
if(move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile )){
$sSQL="INSERT INTO files (title,path,size,extension,userID,catID,dateUploaded) VALUES ('".$title."','".$script_dir.$tmpStr.$upload_dir."/".str_replace(" ","_",$_FILES['Filedata']['name'])."','".$fsize."','".$fileExtensiontmp."','".$_REQUEST["user"]."','".$folderID."',NOW())";
mysql_query($sSQL) or die("Invalid query: " . mysql_error() . " - $sSQL");
addLog($_REQUEST["user"],"Uploaded file $title ");
$msg = "You have successfully uploaded file $title ";
$notice = sendNotice('notify_upload');
if($notice){
//send notice to system mail
send_mail("New file uploaded!", getUser($_REQUEST["user"])." have successfully uploaded file $title");
}
} else {
$msg = "Error! Most likely upload directory doesn't have writable permissions or you didn't set it up correctly. ";
}
//}
} else {
$msg = "Not allowed file extension $fileEXT! ";
addLog($_REQUEST["user"],"Error! Tried to upload $title. Got 'Not allowed file extension' ");
}
} else {
$msg = "File size is larger than you maximum allowed size limit.";
addLog($_REQUEST["user"],"Error! Tried to upload $title. Got 'File size is larger than you maximum allowed size limit.' ");
}
} else {
$msg = "Not enough space left for you on the server. Try deleting some files.";
addLog($_REQUEST["user"],"Error! Tried to upload $title. Got 'Not enough space left for you on the server. Try deleting some files.' ");
}
} else {
$msg = "Your upload quota has been reached. Try deleting some files.";
addLog($_REQUEST["user"],"Error! Tried to upload $title. Got 'Your upload quota has been reached. Try deleting some files.' ");
}
//send_mail("Email Notify",$msg);
echo $msg;
}
exit(0);
?>
据我所见,您正在将上传复制到错误的目录"/var/chroot/home/content/44/9976344/html/tech/filemanager/uploads/"one_answers"/home/contant/44/997644/html/tech-filemanager/uploads/"不相同,如果其中一个是符号链接(很可能)。使用路径"/home/content/44/9976344/html/tech/filemanager/uploads/",而不是使用路径"/var/chroot/home/contant/44/997644/html/tech-filemanager/uploads/"。符号链接只包含有关其链接到的文件的信息。