2

I am trying to use move_uploaded_file but I think everything is fine but my code is not working. Everything is working as expected even image name is being inserted into DB but it is not moving into uploads folder. Folder is there and apache2 does have access to write it.

I don't have enough reputation to post more then 8 lines so everything is on pastebin Here. The main aprt is...

 $post_image_new_name = uniqid('', true). "." 
.$post_image_actual_ext;

                $post_image_destination = '../../uploads/';
                    if (is_dir($post_image_destination) && is_writable($post_image_destination)) {

                    $post_image_destination = '../../uploads/'.$post_image_new_name;
                    var_dump($post_image_destination);
                    move_uploaded_file($post_image_new_name, $post_image_destination);
                    echo "Inside move_uploaded_file section";

https://pastebin.com/Z321R76z

3
  • 1
    Hint: move_uploaded_file() expects the source filename of the uploaded file. It is usually member $_FILES[...]->tmp_name. Commented Apr 21, 2019 at 16:39
  • Warning Please validate Formats before placing them in your directory, any attacker can use this way to upload any type of file. See acunetix.com/websitesecurity/upload-forms-threat Commented Apr 21, 2019 at 19:52
  • Thanks dude I didn't knew such an attack is possible and yes you are right I am a new learner. Commented Apr 22, 2019 at 5:56

2 Answers 2

2

Try this code line 53: move_uploaded_file($_FILES['addPost_post_image']['tmp_name'], $post_image_destination);

The first param should be the file source name.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks brother it has been solved. The problem is as you said it to be. I would love to add a plus but I lack reputation to do so :)
Thank you @MahadAli
Can you upvote my post? lol I got banned from posting question :D
1

move_uploaded_file() expects the source filename of the uploaded file. So you must use something like this:

move_uploaded_file($_FILES['addPost_post_image']['tmp_name'], $post_image_destination);

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.