[英]Unable to upload file to the server
This is my php file for uploading files, but i am getting an error like no such directory whats wrong with my code? 这是我的php文件,用于上传文件,但是我收到一个错误,例如没有这样的目录 ,我的代码有什么问题?
upload.php upload.php
<?php
$vdo=$_FILES['uf']['name']; $target_path = "/photo";
$target_path = $target_path . basename( $_FILES['uf']['name']);
$target_path . basename( $_FILES['uf']['name']);
if(move_uploaded_file($_FILES['uf']['tmp_name'], $target_path))
?>
upload.php file is in the same folder wher my Photo directory is any help is much appriciated! 当我的Photo目录对您有任何帮助时, upload.php文件位于同一文件夹中 !
You need to add /
after the 您需要在
/
之后添加/
$target_path
$target_path = "/photo/";
Due to this, the variable $target_path
is getting folder name prepending to the 因此,变量
$target_path
使文件夹名称前置
file name uploaded. 文件名已上传。
You are creating a path like this: 您正在创建这样的路径:
/photoTheFileName.ext
There are two problems with this: 这有两个问题:
First, you don't have a /
between the directory name and the file name. 首先,目录名和文件名之间没有
/
。
When you fix that: 解决此问题时:
$target_path = "/photo/";
Then the path is the filesystem path, and it will be from the root of the file system. 然后,该路径是文件系统路径,它将来自文件系统的根目录 。
You said: 你说:
upload.php file is in the same folder wher my Photo directory is
upload.php文件位于我的照片目录所在的同一文件夹中
So you want the target path to be something like: 因此,您希望目标路径类似于:
$target_path = "/hosts/www.example.com/htdocs/photo/";
… making the appropriate adjustments for your file system. …对文件系统进行适当的调整。
The error is on line 3, you are adding a slash before the directry name, it must be placed after the path name $target_path="photo/"; 错误发生在第3行,您在目录名称之前添加了一个斜杠,必须将其放置在路径名称$ target_path =“ photo /”之后;
<?php
$vdo=$_FILES['uf']['name']; $target_path = "photo/";
$target_path = $target_path . basename( $_FILES['uf']['name']);
$target_path . basename( $_FILES['uf']['name']);
if(move_uploaded_file($_FILES['uf']['tmp_name'], $target_path))
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.