我在localhost上本地工作,该网站是D / xampp / htdocs / websites / site.com 我也使用这行代码将.php扩展名更改为/(fowardslash)。
从位于site.com/admin/addevent/的页面中,我正在尝试将上传的文件(图像)移至site.com/images/uploads。我正在使用MySQLi和我的PHP代码来做到这一点:
$target = "../images/uploads/";
$target = $target . $_FILES['image']['name'];
$pname = $_FILES['image']['name'];
$ptemp = $_FILES['image']['tmp_name'];
$ptype = $_FILES['image']['type'];
$psize = $_FILES['image']['size'];
if(move_uploaded_file($pname, $target)){
echo "file moved";
}else{
echo "not moved ";
}
答案 0 :(得分:3)
可能希望更改此行以使用临时文件的位置(这是要移动的实际文件的位置)。您正在使用它找到的原始文件的名称,该名称不存在。
if(move_uploaded_file($pname, $target)){
像这样:
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
或者像这样:
if(move_uploaded_file($ptemp, $target)){
答案 1 :(得分:1)
您需要使用文件临时名称。试试这个:
$target = "../images/uploads/";
$target = $target . $_FILES['image']['name'];
$pname = $_FILES['image']['name'];
$ptemp = $_FILES['image']['tmp_name'];
$ptype = $_FILES['image']['type'];
$psize = $_FILES['image']['size'];
if(move_uploaded_file($ptemp, $target)){
echo "file moved";
}else{
echo "not moved ";
}