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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.