dooid3005 2011-07-07 11:56
浏览 56
已采纳

Uploadify:显示PHP错误

How can I send errors caused in back-end PHP file of Uploadify to the uploading form? Right now when I have an error to report to the user from PHP I just echo and it goes to the onComplete method of Uploadify and alerts the user. Please see below:

<?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);
}

if ($error) // I want to show this error on uploading form page.
    {
    echo "Some error";
    } 
else
    {   
    echo '1';
    }
?>

and I get the error like:

'onComplete': function(a, b, c, data, e){
                                alert(data); 
            }
  1. The problem is that I want to get Only error, but it will print "1" if there is no error. I want to print only if there is any error, otherwise dont print 1.
  2. How can i append the error data on the page instead of alert?

Thanks

  • 写回答

5条回答 默认 最新

  • dpf5207 2011-07-07 12:04
    关注

    Have PHP echo 1 if success and an error message if not. Then just check the response back is 1 or something else.

    'onComplete': function(a, b, c, data, e){
      if (data == '1') {
          alert('ok!');
       }
       else {
          alert('Error: ' + data);
       } 
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元