博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php ajax上传图片过大500错误,javascript – JQuery AJAX文件上传错误500
阅读量:1537 次
发布时间:2019-04-21

本文共 1479 字,大约阅读时间需要 4 分钟。

所以我正在尝试使用

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代码来处理文件上传:

$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;

?>

不幸的是,我无法释放实际问题所在的链接,但希望这段代码足以帮助解决问题.如果需要任何其他细节,请不要犹豫,让我知道.

转载地址:http://cysdy.baihongyu.com/

你可能感兴趣的文章
LayUI之select动态赋值的显示问题
查看>>
模拟测试后台请求参数接收问题小结
查看>>
Java8中的LocalDateTime工具类
查看>>
关于使用RestTemplate中请求方法的使用问题总结
查看>>
Mybatis传递多个参数方式
查看>>
Mapper文件中的@Param传参问题
查看>>
安装zookeeper3.5.5闪退的问题
查看>>
Linux 使用rpm方式安装最新mysql(5.7.27)步骤以及常见问题解决
查看>>
Linux服务器云盘挂载简单记录
查看>>
服务器(阿里云)部署项目,并访问项目
查看>>
Java项目中遇到的基础问题记录
查看>>
SpringBoot项目JDK8日期小记
查看>>
最美好的岁月
查看>>
时间与梦想
查看>>
我的心太乱
查看>>
家教与感恩
查看>>
数据结构考研复习要点2016
查看>>
思想汇报(一)——努力的意义
查看>>
RGB转化为YCbCr
查看>>
时间与果实
查看>>