Jump to content

Renaming files in a foreach


graham23s

Recommended Posts

Hi Guys,

 

when users upload files on my site i was wanting each 1 to be renamed to random digits, but im not sure how to do that in a for each my code:

 

     if(isset($_POST['submit'])) {

	foreach($_FILES['file']['name'] as $K => $V) {

     ## Rename the nzb with random digits ###############################################
     $random_number = rand(00000000,99999999);
     $renamed_file = "{$random_number}." . substr($_FILES["file"]["name"],strtolower(strlen($_FILES["file"]["name"]))-3,3);


			$target_path = "uploads/";
			$target_path = $target_path.$renamed_file; 

			//echo $target_path;

			if(move_uploaded_file($_FILES['file']['tmp_name'][$K], $target_path)){

				stderr("Multi-Uploader Successfull","The File's named <b>".$renamed_file."</b> have been uploaded successfully");

			} else {

				stderr("Error","Sorry, there was a technical error.");
			}
		  }

     include("includes/footer.php");
     exit;
     
     }

 

they come out like this:

 

89419555.ray
41931152.ray

 

they are renamed fine but the extensions are .ray i take it because thats in an array

 

any help would be great

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/68080-renaming-files-in-a-foreach/
Share on other sites

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.