gpt4 book ai didi

php - 上传文件到Web服务器错误6 php

转载 作者:行者123 更新时间:2023-12-02 21:21:50 24 4
gpt4 key购买 nike

我正在尝试从 php 表单上传文件。它在 Linux 服务器上不起作用。我希望它将它移动到文件所在的子目录“/uploads”。

执行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>

上传.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 。但没有正确理解。

我还向/uploads授予了完全许可777文件夹。任何帮助将不胜感激。谢谢

最佳答案

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

关于php - 上传文件到Web服务器错误6 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27099537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com