gpt4 book ai didi

javascript - jQuery AJAX 文件上传错误500

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:47:25 26 4
gpt4 key购买 nike

所以我正在尝试使用 JQuery 的 AJAX 进行文件上传,但它一直给我错误 500。

$(function() {
$( 'form' ).submit
(
function()
{
$.ajax({
type: 'POST',
url: 'photochallenge/submit.php',
data: new FormData(this),
processData: false,
contentType: false,
success: function(data) {
Materialize.toast(data, 4000);
}
});
return false;
}
);
});

我也在使用这个 PHP 代码来处理文件上传:

<?php
$target_dir = "uploads/";
$target_file = null;
$uploadOk = 1;
$response = "Please choose an image";
// Check if image file is a actual image or fake image
if(isset($_POST["pic"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
$response = "File is not an image.";
$uploadOk = 0;
}


// Check file size
if ($uploadOk == 1 && $_FILES["fileToUpload"]["size"] > 500000) {
$response = "Sorry, your file is too large.";
$uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {

// if everything is ok, try to upload file
} else {
//find target file
$found = false
$tmp = 0
while(!$found) {
$target_file = $target_dir . $tmp . ".png";
if(file_exists($target_file)) {
$tmp = $tmp + 1;
} else {
$found = true;
}
}

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$response = "Thank you for your submission!";
shell_exec("python log.py ".$_POST["firstname"]." ".$_POST["lastname"]." ".$target_file);
} else {
$response = "Sorry, there was an error uploading your file.";
}
}
}

echo $response;
?>

不幸的是,我无法发布实际问题所在的链接,但希望这段代码足以帮助解决问题。如果需要任何其他详细信息,请随时告诉我。

最佳答案

如果您没有使用“.htaccess”,问题可能出在 shell_exec 中,如果您使用的是 fast-cgi,则可能会导致应用程序崩溃。

注释此行并执行您的脚本:

shell_exec("python log.py ".$_POST["firstname"]." ".$_POST["lastname"]." ".$target_file);

在 PHP 中使用注释:

//shell_exec("python log.py ".$_POST["firstname"]." ".$_POST["lastname"]." ".$target_file);

关于javascript - jQuery AJAX 文件上传错误500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010684/

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