所以我试图做使用jQuery的AJAX的东西文件上传,并不断给我500JQuery的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代码来处理错误文件上传:
$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;
?>
不幸的是,我不能释放链接到实际的问题出在哪里,但希望这个代码是不足以帮助解决问题。如果需要其他细节,请不要犹豫,让我知道。
+0
我将开始与您试图在Ajax调用使用该文件的权限。之后,检查您尝试写入的任何目录的权限,Web服务器需要写入权限。 专门看看代码,shell_exec看起来像许多主机想要在php.ini, –
+0
中禁用的函数是http 500错误还是一些内部逻辑 - 500错误? –
+2
检查服务器的错误日志。您可能正在上传文件超过限制。 –