调试由jQuery调用的PHP文件 [英] Debugging a PHP file called by jQuery
问题描述
我使用uploadify(一个jQuery上传)脚本,后台基本上有一个PHP文件。我想做一些PHP代码的调试(例如看到我在PHP文件中得到什么样的错误(当它被jQuery调用时),但是我不知道如何打印错误,例如原始PHP文件是:
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);
}
?>
现在例如我在上述代码中的move_uploaded_file()之前添加一行。 / p>
Now for example I add a line before move_uploaded_file() in the above code.
die("die befor moving file");
当脚本调用此PHP文件时,它不会转到下一行,但是也不会打印消息,如何打印错误消息?如果可以不可以这样做,可以我显示一些javascript警报消息,想法是知道PHP文件中的错误在哪里。谢谢。
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>
推荐答案
你可以这样做:
$("#fileUpload").fileUpload({
...
'onComplete': function(a, b, c, data, e){
alert(data);
}
});
希望这有帮助。干杯
这篇关于调试由jQuery调用的PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!