Problems with moving selected images to new or existing folder

Function? What function?

If it’s not a function what is this line of code?
move_uploaded_file ($selected, 'uploads/$dirname');

OK, its not calling any class or instantiating one

Can I ask you something? Do you know what I am talking about here?


Try this:

You really should take a look at @Mittineague’s post: #11

@John_Betong I wasn’t trying to be nasty, just thought he never understood what I was getting onto


In your post #9 you have the following:

 <form action="#" method="post">

and in your post:# 1 you have the following:

  move_uploaded_file ($selected, 'uploads/$dirname');   

As mentioned in other posts the function only works if the following has been set:

  <form action="upload_file.php" method="POST" enctype="multipart/form-data">

The enctype must be set.

This will not work.

 <form action="#" method="post">

Did you try the example that I posted? The source code is at the bottom of the page.

In order to move the files I had to use

copy($src,$dst );

Oh of course, because the action has to be set to the self logic page, will try that later on and I will let you know on the copy(), thanks

I think I know. But obviously my efforts to emphasize the importance of being “in the loop” failed miserably.

bool move_uploaded_file ( string $filename , string $destination )

i.e. It doesn’t take an array and therefore needs to be in the loop

Can I assume this line
move_uploaded_file ($selected, 'uploads/$dirname');
got changed to
move_uploaded_file ($selected, 'uploads/'.$dirname);
as $dirname is not being phrased in single quotes?

I don’t think he needs a enctype=“” tag as he’s not uploading images just selecting image names in a form.

… moving selected images from an images folder to an uploads folder.
In that case it would seem the line should read

copy ('images/'.$selected, 'uploads/'.$dirname);


rename('images/'.$selected, 'uploads/'.$dirname);

Both should work Or am I wrong? WRONG. Both above are missing image name but copy() or rename() is what you need.

OK looking at post #1 you want to make a new directory “tempfolder” inside “uploads” then move image.

$dirname = "tempfolder";

if(isset($_POST['submit'])){//to run PHP script on submit
         Loop to store and display values of individual checked checkbox.
        foreach($_POST['image_select'] as $selected){
            if (!file_exists('uploads/'.$dirname)){
            rename('images/'.$selected, 'uploads/'.$dirname.'/'.$selected);        

Hi @Drummin,

Did you try the link in post #11?

It is a working version with six dummy images showing source and destination.

Source code is at the bottom of the page.

Hey John, no sorry I did not open that link from post#24. That’s a cool little interface. But even you were mentioning the enctype=“” tag in post#26 so I thought there was still some confusion on what he was trying to do and the topic was not solved. My bad.

1 Like

Ah, got it, it is finally working, thanks I am using the copy() function