Jump to content

Newbie need simple php help.


Guest

Recommended Posts

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 :)

 

Link to comment
https://forums.phpfreaks.com/topic/94950-newbie-need-simple-php-help/
Share on other sites

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!";
}

?>

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";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.