|
| » 首页 » 电脑_数码 » 编程 » 为什么我用这段php上传代码总是出现这个问题? |
为什么我用这段php上传代码总是出现这个问题? |
|
<html> <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="file.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> </html> //file.php <?php $uploaddir = './var/'; echo $uploaddir ; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo $uploadfile; echo '<br>Come in <br>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; echo 'Here is some more debugging info:'; print_r($_FILES); } ?> 但是上传后总是出现 /bt//bt/bb_qvod.png Come in Warning: move_uploaded_file(/bt/bb_qvod.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/ipower/public_html/bt/upload.php on line 12 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpZkTgsp' to '/bt/bb_qvod.png' in /home/ipower/public_html/bt/upload.php on line 12 Possible file upload attack! Here is some more debugging info:Array ( [userfile] => Array ( [name] => bb_qvod.png [type] => image/png [tmp_name] => /tmp/phpZkTgsp [error] => 0 [size] => 1050 ) ) 还有如何控制上面的文件上传类型 |
![]() |
|
|
去掉basename即可 最好是加个是否上传成功的判断 去掉basename即可 最好是加个是否上传成功的判断 PHP上传文件的代码实例 http://www.phpsu.com/phpjc/20080607/5082.html 上传文件的一些代码 http://www.phpsu.com/phpjc/20080607/5081.html 你看一下这两个网页吧,呵呵 这个错误提示的是:无法将文件复制到指定位置。。我看了你的代码。估计你上传的文件。和你正在编辑的文件。。不是同一个文件。 $uploaddir = './var/'; 这一行代码和你显示出来的不一样。 你用的应该是虎翼网的空间吧。。如果你要上传到 bt 目录。直接这么写就可以了。 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name'])) <form action="xxx.php" method="post" enctype="multipart/form-data"> 少了这句吧enctype="multipart/form-data" 上传实例和详细的讲解 http://www.webphper.cn/naodai/index.php?seekname=%E4%B8%8A%E4%BC%A0&job=searchTitle if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 你这句是怎么移动的 没给文件名好么!!!! 给你个我写的上传类自已去看看吧 class upload{ private $uploadFile; //上传路径 private $uploadType; //数组上传文件类型 private $uploadSize; //上传文件大小 public function __construct($uploadFile , $uploadType , $uploadSize){ $this->uploadFile = $uploadFile; $this->uploadType = $uploadType; $this->uploadSize = $uploadSize; } public function is_upload($name){ $error = new error(); if(!is_uploaded_file($_FILES[$name][tmp_name])){ return $error->alert_msg("文件上传不成功,请重新上传" , 1); } return true; } public function is_uploadSize($name){ $error = new error(); if($_FILES[$name]['size'] > $this->uploadSize){ echo $this->uploadSize; return $error->alert_msg("文件太大了,请压缩后重新上传" , 1); } return true; } public function is_uploadType($name){ $fileType = explode( "." , $_FILES[$name]['name'] ); $count = (count($fileType) - 1); $type = $fileType[$count]; for($i=0;$i<count($this->uploadType);$i++){ $retType .= $this->uploadType[$i].","; } $setType = trim($retType , ","); $error = new error(); if(!in_array( $type , $this->uploadType )){ return $error->alert_msg("上传文件类型错误,只能上传".$setType."类型的文件,请重新上传" , 1); } return true; } public function uploading ($name){ $error = new error(); if($this->is_upload($name) && $this->is_uploadSize($name) && $this->is_uploadType($name)){ if(!file_exists($this->uploadFile)){ mkdir($this->uploadFile , 0777) or die("无法创建目录"); } $fileName = date("Y-m-j" , time())."-".$_FILES[$name]['name']; if(!file_exists($this->uploadFile."/".$fileName)){ if(!move_uploaded_file ($_FILES[$name]['tmp_name'], $this->uploadFile."/".$fileName)){ return $error->alert_msg("文件无法移动,请检查设置" , 1); } }else{ return $error->alert_msg("上传文件已存在,请重新上传" , 1); } } return true; } } |
| 《为什么我用这段php上传代码总是出现这个问题?》答案收集时间:2008-06-14 14:28:52 |