gpt4 book ai didi

php - 无法上传文件 - php & mysql

转载 作者:行者123 更新时间:2023-11-28 23:22:56 24 4
gpt4 key购买 nike

我确实尝试将文件上传到系统中。它确实通过了上传到系统的所有必要要求。但是文件仍然没有上传到它。

这是我发现错误发生的精确位置。

因为系统只读取给定的输出:

System is busy. Please try again laterb

if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
//echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
} else {
$msg = 'System is busy. Please try again laterb';
goto ERROR;
}

下面的代码是对系统上的电子邮件帖子的完整解析。

$email_params = array('fromEmail' => $_SESSION['user']['usr_id'], 'toEmail' => $to, 'subject' => $_POST['subject'], 'message' => $_POST['description'], 'addCC' => $cc);
$email = sendmail($email_params, 2);

if (!$email) {
$msg = 'Failed to send email.';
goto ERROR;
}

// Begin Upload FIle
$msg = "System is busy. Please try again later!";
$target_dir = "./images/ticket_attachments/";
$temp = explode(".", $_FILES["file"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
$target_file = $target_dir . $newfilename;
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);

if ($imageFileType != '') {
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["file"]["tmp_name"]);
if ($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
$uploadOk = 0;
$msg = 'File is not an image';
goto ERROR;
}
}

// Check if file already exists
if (file_exists($target_file)) {
$uploadOk = 0;
$msg = 'Sorry, file already exists';
goto ERROR;
}

// Check file size
if ($_FILES["file"]["size"] > 500000) {
$uploadOk = 0;
$msg = 'Sorry, your file is too large. Your file must be less than 500KB';
goto ERROR;
}

// Allow certain file formats
if ($imageFileType != "png" && $imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "txt" && $imageFileType != "doc" && $imageFileType != "docx" && $imageFileType != "xml" && $imageFileType != "pptx" && $imageFileType != "gif" && $imageFileType != "ppt" && $imageFileType != "xps" && $imageFileType != "pptm" && $imageFileType != "zip" && $imageFileType != "csv" && $imageFileType != "xlsx" && $imageFileType != "xls" && $imageFileType != "rar" && $imageFileType != "mp4") {
$uploadOk = 0;
$msg = 'Sorry, files not supported. Only jpg, jpeg, png, docx, pdf, zip, xlsx files are supported.';
goto ERROR;
}

if ($uploadOk == 0) {
$msg = 'System is busy. Please try again latera';
goto ERROR;
// if everything is ok, try to upload file
} else {
$temp = explode(".", $_FILES["file"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
//echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
} else {
$msg = 'System is busy. Please try again laterb';
goto ERROR;
}
}
} else {

$newfilename = '';
}

请帮忙。谢谢。

最佳答案

上传文件夹(./images/ticket_attachments/ 在你的例子中)应该可以通过 PHP 访问。

如果您在 Linux 上运行:chmod -R 777 ./images/

在 Windows 上:文件夹属性 -> 安全 -> 每个人/编辑 -> 授予对每个人的完全控制权

关于php - 无法上传文件 - php & mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40738552/

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