JQuery AJAX文件上传错误500

So I'm trying to do a file upload using JQuery's AJAX thing, and it keeps giving me the error 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;
        }
    );
});

I am also using this PHP code to process the file upload:

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

Unfortunately, I cannot release the link to where the actual problem is, but hopefully this code is enough to help solve the problem. If any other details are needed, please do not hesitate to let me know.

douzhuolong9886
douzhuolong9886 那么错误信息是什么意思呢?
5 年多之前 回复
dsfds4551
dsfds4551 检查服务器的错误日志。您可能正在上传文件超出限制。
5 年多之前 回复
dongqian9013
dongqian9013 是http500错误还是一些内部逻辑--500错误?
5 年多之前 回复
dongmoxin7111
dongmoxin7111 我将从您尝试在ajax调用中使用的文件的权限开始。在您尝试写入的任何目录上的检查权限之后,Web服务器需要写入权限。具体看一下代码,shell_exec看起来像许多主机想要在php.ini中禁用的函数,
5 年多之前 回复

1个回答



如果您没有使用“.htaccess”,则问题可能出在可能崩溃的 shell_exec </ code>中 应用程序,如果你使用的东西是fast-cgi。</ p>

注释这一行并执行你的脚本:</ p>

  shell_exec(“python”  log.py“。$ _ POST [”firstname“]。”“。$ _ POST [”lastname“]。”“。$ target_file); 
</ code> </ pre>

使用注释 在PHP中:</ p>

  // shell_exec(“python log.py”。$ _ POST [“firstname”]。“”。$ _ POST [“lastname”]。“”。  $ target_file); 
</ code> </ pre>
</ div>

展开原文

原文

If you are not using ".htaccess", the issue may be in the shell_exec that may be crashing the application, if you are using something as fast-cgi.

Comment this line and perfom your script:

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

Using comments in PHP:

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

立即提问
相关内容推荐