Chrisj Posted October 30, 2014 Share Posted October 30, 2014 In the PHP script I'm using, in the Upload Form the user selects an image to Upload, the Form renames it like so: $allowedExts = array("gif", "jpeg", "jpg", "pdf", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if (!in_array($extension,$allowedExts)) { echo ("Error - Invalid File Name"); } $length = 20; $randomString = (time()); $thumbnail = $randomString . "." . $extension; The random string works successfully, but I'd like to add the user_id to the beginning of it and a dash, like this: user_id - So, the new file name would be something like: user_id-randomString.extension Can you please help me add that? Quote Link to comment https://forums.phpfreaks.com/topic/292167-add-the-user_id-to-the-random-string/ Share on other sites More sharing options...
ginerjm Posted October 30, 2014 Share Posted October 30, 2014 I've seen this code before. Copy it from somewhere? Anyway - what you want to do is no different than what you are doing to build $thumbnail, altho as I recall from before $thumbnail never gets used. PS - a 'form' doesn't do any renaming of your file. PHP code does it. Also - what is your script supposed to do when if finds an invalid extension? According to your code it proceeds along its merry way trying to rename the file and do whatever else you haven't shown us. Quote Link to comment https://forums.phpfreaks.com/topic/292167-add-the-user_id-to-the-random-string/#findComment-1495265 Share on other sites More sharing options...
Chrisj Posted October 30, 2014 Author Share Posted October 30, 2014 Thanks for your reply, but I don't know how to add "user_id -" "to build $thumbnail" any additional help will be apprecaited. Quote Link to comment https://forums.phpfreaks.com/topic/292167-add-the-user_id-to-the-random-string/#findComment-1495278 Share on other sites More sharing options...
ginerjm Posted October 30, 2014 Share Posted October 30, 2014 This code (your code?) creates a variable called $thumbnail. It does it by concatenating 3 things. So - follow that example and concatenate user id and whatever else you want to include in your filename. Perhaps you should be reading some introductory php manuals/books/references in order to understand basic syntax. What I am showing you is Very Basic so if you can't follow it you will find learning php vary difficult. Quote Link to comment https://forums.phpfreaks.com/topic/292167-add-the-user_id-to-the-random-string/#findComment-1495289 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.