How can I upload a single file (ex.sample.jpg) in more than one folder (ex. folder1 and folder2) using php
I tried using for loop but it wont work its move the file (sample.jpg) to the first folder (folder1) only, while moving the same file to the second folder (folder2) it throws an error
You can create a copy of the before moving it to the first directory, then move the copy into the second directory.
copy() function to copy the file.
Your code should look something like this -
$firstDestination = "path/to/your/firstDirectory/" . $_FILES['userfile']['name']; $secondDestination = "path/to/your/secondDirectory/"; move_uploaded_file($_FILES['file']['tmp_name'], $firstDestination ); copy($firstDestination, $secondDestination);