graham23s Posted September 5, 2007 Share Posted September 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/68080-renaming-files-in-a-foreach/ Share on other sites More sharing options...
lemmin Posted September 5, 2007 Share Posted September 5, 2007 This part: substr($_FILES["file"]["name"],strtolower(strlen($_FILES["file"]["name"]))-3,3); Is returning "Array," probably. strlen() returns a number so you are passing a numerical value to strtolower(), which doesn't make sence. Quote Link to comment https://forums.phpfreaks.com/topic/68080-renaming-files-in-a-foreach/#findComment-342204 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.