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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?