Reputation: 1682
I have an uploading form, and when i select the file,i need it to be uploaded in multiple folders.Any ideas how to do that? I've tried with a loop like the following one:
foreach($_POST['check'] as $check){
move_uploaded_file($_FILES['doc']['tmp_name'], $target_path);
chmod($target_path,0777);
}
But it only upload once.Any ideas please?
Upvotes: 0
Views: 4027
Reputation: 1
$i = 0;
foreach($_POST['check'] as $check){
$basePath = "/var/www/html/more/phpexm/";
$target_path = $basePath . $check;
if (!file_exists($target_path)){
mkdir($target_path, 0777);
}
if ($i == 0){
$sFileNameTmp = $_FILES['doc']['tmp_name'];
$sFileName = $_FILES['doc']['name'];
move_uploaded_file($sFileNameTmp, $target_path . '/' . $sFileName);
$sFirstFileUploaded = $target_path;
}
else{
copy ($sFirstFileUploaded . '/' . $sFileName, $target_path . '/' . $sFileName);
}
$i++;
}
Upvotes: 0
Reputation:
After uploading, copy the file from the target path to the other paths with copy().
foreach($_POST['check'] as $check){
move_uploaded_file($_FILES['doc']['tmp_name'], $target_path);
chmod($target_path,0777);
// and now...
copy($target_path, $target_path_2);
copy($target_path, $target_path_3);
// etc...
}
By the way, setting 0777 for permissions generally is unnecessary and a bad idea. You want anyone to upload files and let any user execute them? That's the way to start giving anyone full control over your machine.
Also, are you sure that you need the file on multiple places? Why not have one common storage folder and create symbolic links to it? But that depends on your setup, of course.
Upvotes: 3