ajax上传文件报错500,JQuery的AJAX文件上传错误500

所以我试图做使用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

检查服务器的错误日志。您可能正在上传文件超过限制。 –

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值