将图像上传到目录时出错

时间:2015-01-20 01:47:24

标签: php upload

当我尝试将图像上传到我的目录时,我继续收到这些警告:

  

警告:move_uploaded_file(localhost / school / photo / IMG_3036.PNG):   无法打开流:没有这样的文件或目录   第20行的C:\ xampp \ htdocs \ school \ Pages \ upload.php

     

警告:move_uploaded_file():无法移动   'C:\ xampp \ tmp \ phpDE6A.tmp'到'localhost / school / photo / IMG_3036.PNG'in   第20行的C:\ xampp \ htdocs \ school \ Pages \ upload.php

CODE:

 <form action="upload.php" method="post" enctype="multipart/form-data">
 <input type="file" name="upload" /> &nbsp; <input type="submit" name="btn_upload" value="UPLOAD" />
 </form> 
<?php 
if (isset($_POST['btn_upload']))
{
$filetmp = $_FILES["upload"]["tmp_name"];
$filename = $_FILES["upload"]["name"];
$filetype = $_FILES["upload"]["type"];
$filepath = "localhost/school/photo/".$filename; 
 move_uploaded_file($filetmp,$filepath); //LINE 20

$con = mysqli_connect ("localhost" , "web" , "" , "imagestore") or die ("could not connect"); 
 $sql = "INSERT INTO upload_img (img_name,img_path,img_type) VALUES ('$filename','$filepath','$filetype')";

 $result = mysqli_query($con,$sql) or die("error");

} 

 ?> 

HERES我的目录,

c:xammp\htdocs\school\photo

1 个答案:

答案 0 :(得分:0)

move_uploaded_file需要文件系统路径,而不是url路径作为目标。你正在通过一个网址路径。假设您有权写入该文件夹,设置正确的$filepath应该有效:

$filepath = "C:\\xampp\\htdocs\\school\\photo\\".$filename;

因为这是计算机上照片目录的实际路径。