sunjie
sunjie

Reputation: 2053

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>

Upvotes: 3

Views: 1798

Answers (4)

chiborg
chiborg

Reputation: 28104

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

Upvotes: 1

zzarbi
zzarbi

Reputation: 1852

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>

Upvotes: 0

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18354

You can do it like this:

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

Hope this helps. Cheers

Upvotes: 0

run
run

Reputation: 1186

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.

Upvotes: 1

Related Questions