-1

我在下面有一个 javscript 函数,它根据结果显示一条消息:

   function stopImageUpload(success){
          var result = '';
          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
          }
          else {
             result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
          }  
          return true;   
    }

下面的代码总是显示消息“文件已成功上传!”

   <?php

       $destination_path = str_replace("//", "/", $_SERVER['DOCUMENT_ROOT']."/")."ImageFiles";

       $result = 0;

       $target_path = $destination_path . basename( $_FILES['fileImage']['name']);

       if(move_uploaded_file($_FILES['fileImage']['tmp_name'], $target_path)) {
          $result = 1;
       }

       sleep(1);

    ?>

   <script type='text/javascript' language='javascript'>
      window.top.window.stopImageUpload(1);
   </script>

但是,如果我将最后一行更改为下面的内容,则它始终会显示消息“文件上传期间出错!”。为什么会这样,如何解决它,以便根据结果显示正确的消息?

<script language="javascript" type="text/javascript">
  window.top.window.stopImageUpload(<?php echo $result; ?>);
</script>
4

1 回答 1

1

找出这<?php echo $result; ?>实际呈现的内容。只需查看页面源。

最有可能的是0。然后尝试找出move_uploaded_file返回 false 的原因。移动文件时可能发生了错误。

于 2012-04-11T14:31:35.153 回答