Mahad Ali
Mahad Ali

Reputation: 77

Php Problem with move_uploaded_file. It seems everything is fine but it is not working

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

Upvotes: 2

Views: 110

Answers (2)

Morteza Pouretemadi
Morteza Pouretemadi

Reputation: 648

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

Upvotes: 1

Fatih khan
Fatih khan

Reputation: 84

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.

Upvotes: 2

Related Questions