php ajax上传图片过大500错误,javascript – JQuery AJAX文件上传错误500
发布日期:2021-06-24 13:24:42 浏览次数:4 分类:技术文章

本文共 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;

?>

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

转载地址:https://blog.csdn.net/weixin_33137081/article/details/115990585 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:matlab 图中的legend,matlab中legend加图示命令的使用
下一篇:iis运行不起来php报500,解决IIS上安装thinkphp6运行报500错误

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月29日 02时19分44秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章