我正在尝试上传一个来自php的文件,form.It不会在linux服务器上工作。我希望它将它从文件所在的位置移动到子目录“/上载”。
当echo $_FILES["file_upload"]['error'];执行页面以获得错误号时,我会得到以下错误。
返回的 :
Upload failed with error code 6有人知道这个错误代表什么吗?
表单代码:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select File to upload:
<input type="file" name="file_upload" id="file_upload">
<input type="submit" value="Upload File" name="submit">
</form>
</body>
</html>upload.php :
<?php
if(isset($_POST['submit']))
{
if($_FILES['file_upload']['name'] != "" )
{
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file_upload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$uploadOk = 1;
}
else
{
die("No file specified!");
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["file_upload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "txt" && $imageFileType != "xls" && $imageFileType != "xlsx")
{
echo "Sorry, only TXT, XLS, XLSX files are allowed.";
$uploadOk = 0;
}
if ($_FILES["file_upload"]['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES['file_upload']['error']);
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["file_upload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["file_upload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
?>我已经搜索了这个问题并找到了Here的解决方案。但不能正确地站起来。
我还授予777对/uploads文件夹的完全权限。任何帮助都将不胜感激。谢谢
发布于 2014-11-24 07:12:00
UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 5.0.3.http://php.net/manual/en/features.file-upload.errors.php
修正你的设置..。
http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir
发布于 2017-10-12 14:23:16
我在SELinux上使用"setenforce 0“进入许可模式解决了这个问题;
[root@localhost tequila]# setenforce 0发布于 2020-01-20 14:10:54
如果文件上载以前工作正常,并且/tmp文件夹用于上传文件,那么只需重新启动apache服务就可以解决这个问题:
在ubuntu中,可以使用以下命令重新启动apache服务:
sudo /etc/init.d/apache2 restarthttps://stackoverflow.com/questions/27099537
复制相似问题