0

I am having a problem with move_uploaded_file().

I am trying to upload a image path to a database, which is working perfectly and everything is being uploaded and stored into the database correctly.

However, for some reason the move_uploaded_file is not working at all, it does not produce the file in the directory where I want it to, in fact it doesn't produce any file at all.

The file uploaded in the form has a name of leftfileToUpload and this is the current code I am using.

 $filetemp = $_FILES['leftfileToUpload']['tmp_name'];
 $filename = $_FILES['leftfileToUpload']['name'];
 $filetype = $_FILES['leftfileToUpload']['type'];
 $filepath = "business-ads/".$filename;

This is the code for moving the uploaded file.

move_uploaded_file($filetemp, $filepath);

Thanks in advance

miotk
  • 37
  • 1
  • 10

4 Answers4

3

Try this

$target_dir = "business-ads/";
$filepath = $target_dir . basename($_FILES["leftfileToUpload"]["name"]);
move_uploaded_file($_FILES["leftfileToUpload"]["tmp_name"], $filepath)

Reference - click here

Kamran Khatti
  • 3,754
  • 1
  • 20
  • 31
0

Try using the real path to the directory you wish to upload to.

For instance "/var/www/html/website/business-ads/".$filename

Also make sure the web server has write access to the folder.

Blinkydamo
  • 1,582
  • 9
  • 20
  • I tried that.. "/httpdocs/business-ads/" still doesn't do anything in there – miotk Oct 04 '16 at 13:16
  • What type of webserver are you running? – Blinkydamo Oct 04 '16 at 13:17
  • Plesk I believe the web server is – miotk Oct 04 '16 at 13:18
  • Not sure if this will help but have a look at teh output from this and see if it works for you, I don't have much knowledge of hosted server as I run my own. `` – Blinkydamo Oct 04 '16 at 13:21
  • I have yes and it just states that its failed to open stream, there is no such file or directory. – miotk Oct 04 '16 at 13:21
  • Have a look at this [http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory/36577021#36577021](Link) – Blinkydamo Oct 04 '16 at 13:23
  • I've tried that, I know the directory does exist with the correct permissions so I can't understand why it isn't copying them over to the directory – miotk Oct 04 '16 at 13:37
0

make sure that your given path is correct in respect to your current file path. you may use.

if (is_dir("business-ads"))
{
    move_uploaded_file($filetemp, $filepath);
} else {
    die('directory not found.');
}
NXT
  • 1,981
  • 1
  • 24
  • 30
Pradyut Manna
  • 588
  • 1
  • 3
  • 12
0

You need to check following details :

1) Check your directory "business-ads" exist or not.

2) Check your directory "business-ads" has permission to write files.

You need to give permission to write in that folder.

Vivek Pipaliya
  • 488
  • 1
  • 7
  • 17