Debugging a PHP file called by jQuery

跟風遠走 提交于 2019-12-23 18:35:23

问题


I'm using uploadify (a jQuery uploading) script, which has basically a PHP file at the backend. I want to do some kind of debugging of PHP code, (for example see what kind of errors I get in the PHP file (when it's called by jQuery), but I don't know how I can print the errors. For example the original PHP file is:

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    move_uploaded_file($tempFile,$targetFile);
}   
?>

Now for example I add a line before move_uploaded_file() in the above code.

die("die befor moving file");

When this PHP file is called by the script, it won't go to the next line but it wont print the message either. How can I print the error message? If it can't be done this way, can I display some javascript alert message. The idea is to know where the error in the PHP file is. Thanks.

Here's the front end uploading page code:

<script type="text/javascript">

$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed'
    });

});

</script>
</head>

<body>
    <fieldset style="border: 1px solid #CDCDCD; padding: 8px; ">
        <legend><strong>Uploadify Sample</strong></legend>
        <h2>Single File Upload</h2>
        <p>Display speed</p>
        <div id="fileUpload">You have a problem with your javascript</div>
    </fieldset>
</body>
</html>

回答1:


You can do it like this:

$("#fileUpload").fileUpload({
   ...
   'onComplete': function(a, b, c, data, e){
       alert(data);
    }
});

Hope this helps. Cheers




回答2:


if your using apache server get httpd.conf file and search for ErrorLog log location and open the log file you will have proper error message to debug the issue.




回答3:


You could use the FirePHP library + Firefox extension to print error messages in PHP that are visible in your browser.




回答4:


The Upload process is actually done by a flash "uploadify/uploader.swf" some flash uploader came with a debug mode so you can see the response from PHP.

Worst case you can tell PHP to write some debug line into a external log file with put_file_contents

[EDIT:] According this page http://www.uploadify.com/forums/discussion/2085/built-in-debug/p1 Uploadify doesn't come with a debug mode. So you are better writing in a log file with file_put_contents Also this flash works like a normal HTML form (except that flash can retrieve a percentage of uploading), so you can create a simple HTML form thant send a file through your PHP such as:

<html>
<head>
   <title>Upload file</title>
</head>
<body>
   <form id="form" method="post" enctype="multipart/form-data" action="yourFile.php">
       <input type="file" name="Filedata" />
       <input type="submit" value="Upload" />
   </form>
</body>
</html>


来源:https://stackoverflow.com/questions/6578451/debugging-a-php-file-called-by-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!