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条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化