douyi0902 2015-10-27 14:39
浏览 140
已采纳

在form =“action”调用的警告框中显示PHP函数的输出

Basically, i'm using a <form action=MyPhp.php> to upload a file from the client to my server. When the upload is successfull (or not), i send back a message to the client to show the result (success or failed).

Here is the trick : i don't know how to catch that message. If it was only javascript/php i would use XMLHttpRequest(), but i think it can be way easier. I already checked the parameter "onsubmit=" and "target=", but i don't know how to access to the message. My goal would be to show the message as a javascript:alert("The message from php"). Any suggestions would be appreciated. Here is my code:

HTML

<form action="Upload.php" method="post" enctype="multipart/form-data">
    <div class="custom-button-style browse-button-style" onclick="Browse()">Browse part</div>
    <input class="toHide" type="file" id="fileToUpload" name="fileToUpload" data-role="none"/>
    <input class="toHide" type="submit" value="Upload Part" id="submit" name="submit"  data-role="none"/>
</form>

PHP

<?php
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

if($imageFileType != "zip" )
{
    echo "The file selected doesn't have the right extension. Please select a .zip file.";
    $uploadOk = 0;
}

if($uploadOk == 1)
{
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
    {
        $zip = new ZipArchive();
        $res = $zip->open($target_file);
        if($res == TRUE)
        {
            $zip->extractTo($target_dir);
            $zip->close();
            unlink($target_file);
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
        }
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file.";
    }
}
else
{
    echo "Sorry, your file was not uploaded.";
} 
?> 
  • 写回答

1条回答 默认 最新

  • duan1933 2015-10-27 14:45
    关注

    you coud try something like this:

      echo "<script language='JavaScript' type='text/javascript'>";
         echo "alert('your message');";
      echo "</script>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥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美术毛发渲染