1

While uploading images files on the live server I have stuck in a strange issue that the move_uploaded_files() function returns true but the image does not get uploaded.

if(move_uploaded_file($_FILES["img"]["tmp_name"],'./shot_images/'.$_FILES["img"]["name"])){
  echo "Success";
}

Here, when executed, prints "Success" but the file is not being uploaded on the specified location.

Any kind of help is appreciated.

5
  • Does PHP has write rights on /shot_images/? Commented Nov 4, 2011 at 12:09
  • 1
    @powtac this is wrong question to ask. Commented Nov 4, 2011 at 12:09
  • Test it with php.net/manual/en/function.is-writable.php Commented Nov 4, 2011 at 12:10
  • I found a similar question stackoverflow.com/questions/5655859/… Commented Nov 4, 2011 at 12:12
  • @Awea that's the opposite problem. move_uploaeded_file there returns false. Commented Nov 4, 2011 at 12:19

1 Answer 1

1

If move_uploaded_file is returning true then that indicates the file was moved successfully. Let's try some debugging. What happens when you use the following code:

$dest = "./shot_images/{$_FILES["img"]["name"]}";
if(move_uploaded_file($_FILES["img"]["tmp_name"],$dest)){
  $realpath = realpath($dest);
  $filesize = filesize($realpath);
  echo "Success! Uploaded a $filesize file to $realpath";
}

I suspect it is working, it's just not going where you expect...

If this is the case, it might be due to `'./shot_images/' -- personally I rarely (if ever) use relative paths like that. I find it eliminates confusion if I reference the path to the script:

$dest = dirname(__FILE__)."/shot_images/{$_FILES["img"]["name"]}";
if(move_uploaded_file($_FILES["img"]["tmp_name"],$dest)){
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.