Search code examples
phpjquerydebugginguploaduploadify

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>

Solution

  • You can do it like this:

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

    Hope this helps. Cheers