Guest Posted March 7, 2008 Share Posted March 7, 2008 hi im new to here and already i have picked up quite a bit My question is : I have a folder which files get uploaded into and i need these to be moved to another folder say e.g from a uploads to stored. I dont know what the uploaded files will be called and need it to move all the files in the folder? is this poissble? Hope ya can help Quote Link to comment Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 have a look at www.php.net/glob Quote Link to comment Share on other sites More sharing options...
rofl90 Posted March 7, 2008 Share Posted March 7, 2008 glob isn't essential heres my script to upload files <?php $target_path = $_POST['dir']; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, we are redirecting you now!"; echo "<meta http-equiv=\"refresh\" content=\"0;index2.php?upload=Congratulations your file was uploaded!\">"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted March 7, 2008 Share Posted March 7, 2008 So your $target_path would be ma9ic's "uploaded" directory. Later, he wants to move them "stored". What's your objection to glob()? Quote Link to comment Share on other sites More sharing options...
Guest Posted March 7, 2008 Share Posted March 7, 2008 got it working now <?php //************* CONFIG *******************/ //Set the folder to look for pics in. (no /) $dir = "home/uploads"; //Set the maximum number of pics for each dir $max = 300; //Where do you want to save them? (no /) // MAKE SURE THIS EXISTS AND IS CHMOD 777!! //Don't put it in the same folder as your originals either.. $copyPath = "home/galleryinports"; //Prefix, if any, to add to the folder name.. new folder names will be prefix1 prefix2 prefix3... $prefix = ""; //List of prefixes to copy.. ALL CAPS $fileTypes = array("JPG","JPEG","GIF","BMP"); //Thats it!!! //******* You shouldn't need to edit below this line ***********************/ CopyDirContents($dir,$max,$fileTypes,$copyPath,$prefix); function CopyDirContents($dir,$max,$fileTypes,$copyPath,$prefix=null){ ini_set("max_execution_time",6000); if (!is_dir($dir)){die ("Error::Not a directory: $dir!");} $totalFiles = 0; $dirNum = 0; $cur = 1; $curDir = $copyPath."/"; if ($root=@opendir($dir)){ while ($file=readdir($root)){ if($file=="." || $file==".."){continue;} if(is_dir($dir."/".$file)){ continue; }else{ $fileParts = explode(".",$file); if(!is_array($fileParts) || !in_array(strtoupper($fileParts[count($fileParts)-1]),$fileTypes)) {continue;} if($cur > $max) { $dirNum++; $curDir = $copyPath."/"; mkdir($curDir); $cur = 1; } copy($dir."/".$file,$curDir."/".$file); print $file."\t\t\t=>\t".$curDir."/".$file."\n"; $cur++; $totalFiles++; } } } print "\nCopied $totalFiles files into ".$dirNum." directories.\n"; } ?> Quote Link to comment Share on other sites More sharing options...
rofl90 Posted March 7, 2008 Share Posted March 7, 2008 No objection. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.