简体   繁体   中英

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?

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!

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

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

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/";

<?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))
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM