Hello.
I have a multi file uploader that is working great. However, now I am trying to upload two different files into separate folders during each iteration of the loop from the multiloader.

The client is wanting an image in one folder and a thumbnail into another folder. They have decided that they want the thumbnail to be a totally different image, not a resized version of the main image.

What I was thinking is having a folder populated with all the main images, and in the same folder all the thumbnail icons in the same folder and titled the same, but with "_th" added before the extension ( fileone.jpg, fileone_th.jpg, filetwo.jpg, filetwo_th.jpg, ...), so the client could just pick all the main images for the multiloader and the php script would upload the main ones, but also upload the thumbnails into their folder.

Here is a very stripped down version of the script and I have tried some variances with no luck. Only the first main set of images are uploaded, not the thumbnail versions. Remember, these are different images than the first set, so I can't use copy(). I know one solution is to simply make the client use a different form just for the thumbnails, but it is a massive amount of images as well as some database records linking the main and thumb image, so I was hoping to just streamline the process right at the point of uploading.

  if ($_POST[SubmitB] == "Upload File")
  {

$tmpfile = $_FILES['uploadFile'] ['tmp_name'];

$pieces = explode(".", $tmpfile);
$thumbname = $pieces[0] . "_th." . $pieces[1];

   move_uploaded_file ($tmpfile, "folder1/{$_FILES['uploadFile'] ['name']}");
   move_uploaded_file ($thumbname, "folder2/{$_FILES['uploadFile'] ['name']}");

echo "File uploaded.";
}

I am assuming that the script ends after executing move_uploaded_file() or something simple I am just not aware of.

I appreciate any ideas of maybe a better way to approach this.

Thanks for your time!!

    Are the thumbnail files being uploaded?

      Umm... read the documentation on [man]move_uploaded_file[/man]. It states:

      move_uploaded_file( string $filename, string $destination)

      I think you may have mixed up your order of parameters. Not to mention that you craete $thumbname, but never use it 🙁

      also, if you are dealing with multiple file uploads, then you should do a quick print_r() of the$_FILES array to see exactly how it's set up. That way you can work with it in your code. Right now, you're going on the assumption that there is only one file uploaded named "uploadfile" and it is being copied to two spots. This is in direct contradiction to what you say the customer wants. So it's quite possible that you're not even dealing with a real file, but rather just an array so nothing is happening 😉

        Hi HalfaBee.
        The thumbs aren't getting uploaded, just the main images.

        Thanks bpat1434.
        Guess I'm still not seeing it but it looks like on that second move_uploaded_file function, I am targeting that $thumbname var I created. Anyway, if I had bothered to look, I see the tmp_name that php creates looks nothing like the normal name, so all that name formatting for the second image file was useless. I did get the file to copy to two different directories by creating two different tmp files and then using two copy statements, but it still isn't exactly what I was looking for.

        I think I will approach this with two upload forms after all, one for the main images and one for the thumbs.

        Thanks very much for your time!

          You don't need to though. You can do it in one. Show us your form as it is now. We can give you pointers for your code 🙂

            11 years later
            Write a Reply...