尝试移动上传的文件以使其保存在目录中,则失败。我使用echo ($_FILES['company_logo'] ['error']);
来获取错误编号。我唯一可以找到的错误号是http://www.htmlgoodies.com/beyond/php/article.php/3472561/PHP-Tutorial-Error-Handling.htm。但是,他们的列表只能达到4,并且我得到了错误号6.有谁知道这个错误代表什么?这里是我的代码:move_uploaded_file错误6 php
$allowed_filetypes = array('.jpg','.jpeg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = '../images/companies/'; // The place the files will be uploaded to (currently a 'files' directory).
if($_FILES['company_logo']['name'] != "") {
if($row['image'] != ''){
unlink("../".$row['image']);
}
$filename = $_FILES['company_logo']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
$ext = strtolower($ext);
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['company_logo']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
$ran = rand();
$filename = $ran.$ext;
if(move_uploaded_file($_FILES['company_logo']['tmp_name'],$upload_path.$filename)){ // This is where it fails
$file = $upload_path.$filename;
$result = mysql_query("UPDATE Companies SET image = 'images/companies/$filename' WHERE id = '$id';");
if($result)
$_SESSION['message'] .= "<p class='copy' style='color:red;'>Your image upload was successful.</p>"; // It worked.
else
$_SESSION['message'] .= "<p class='copy' style='color:red;'>Unable to upload image(s).</p>";
}else{
$_SESSION['message'] .= "<p class='copy' style='color:red;'>Unable to upload image(s).</p>";
echo ($_FILES['company_logo'] ['error']);
die();
}
}
正如你所看到的,我做检查的实际文件被上传,如果文件扩展名是在允许的文件类型的列表,如果文件超过最大文件大小,路径是否可写。所以我不相信这是任何事情,但我不确定。任何帮助,将不胜感激。
谢谢。我确实在那里,但没有看到一个列表。 – James 2012-01-03 22:11:00
所以,鉴于这是答案,如何去解决它? – d2burke 2012-07-23 14:56:27
通过在php.ini中设置正确的可写路径:http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir – 2012-07-23 20:18:40