当我尝试将图像上载到我的目录时,我不断收到这些警告:
警告:move_upload_文件(localhost/school/photo/IMG_3036.PNG):无法打开流:C:\xampp\htdocs\school\Pages\upload中没有此类文件或目录。php在线20
警告:move_uploaded_file():无法将C:\xampp\tmp\phpDE6A. tmp移动到第20行C:\xampp\htdocs\School\Pages\upload.php中的localhost/school/photo/IMG_3036.PNG
代码:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="upload" /> <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");
}
?>
这是我的目录,
c:xammp\htdocs\school\photo
move\u upload\u file
需要一个文件系统路径,而不是url
路径作为目标。您正在传递url路径。假设您有写入文件夹的权限,设置正确的$filepath
应该可以:
$filepath=“C:\\xampp\\htdocs\\school\\photo\\”$文件名代码>
因为这是您计算机上到照片目录的实际路径。