1

以下是我在 IE 9 - Windows 7 中使用 php 上传文件的代码

与文件上传过程相关的问题 - 相同的代码在其他浏览器中工作

测试.html

<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="uploader.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

上传者.php

<?php

if( $_FILES['file']['name'] != "" ) { print_r($_FILES); copy( $_FILES['file']['name'], "/var/www/html/php/uf" ) or die( "Could not copy file!");

} else { die("No file specified!"); } ?>
4

1 回答 1

1

尝试这个 。

当一个文件已经上传到服务器上时,它的真实路径是$_FILES['file']['tmp_name'], NOT $_FILES['file']['name'], 不要使用copy(), 使用move_uploaded_file, 更安全

<?php

if(!empty($_FILES)) { 

      if(is_uploaded_file($_FILES['file']['tmp_name'])){
            $tmp_name = $_FILES['file']['tmp_name'];
            $new_name = "/var/www/html/php/uf/".$_FILES['file']['name'];
            if(!move_uploaded_file($tmp_name, $new_name)){
                 exit('Could not move the file');
            }

      }else{
           exit('not uploaded file');
      }
      //copy( $_FILES['file']['name'], "/var/www/html/php/uf" ) or die( "Could not copy file!");
      //DO NOT use copy for uploaded file , it's unsafe.

} else { 
   exit("No file specified!");
} 
?>
于 2012-09-28T05:49:34.433 回答