Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a PHP file called by jQuery

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>
like image 627
sunjie Avatar asked May 09 '26 05:05

sunjie


2 Answers

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.

like image 85
run Avatar answered May 11 '26 17:05

run


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

like image 43
chiborg Avatar answered May 11 '26 18:05

chiborg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!