Hi, I am rewriting a file uploading script in php. I would like to add a string of random number after the file name. May i know how can it be done ? example: $filename=mypicture_jpg(random number) Below is my current code: $filename = $_FILES['upfile']['name']; $filename= str_replace(".","_",$filename); PHP:
int rand ( [int min, int max]) If called without the optional min, max arguments rand() returns a pseudo-random integer between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15). so basically you can just do something like $filename = $filename.rand(1000,5000); Code (markup):
Thanks. That's exactly what i want. I have another problem now, sorry i am new in php = ) i cant change the "space" into "_" ? Anything wrong this these line ? $filename = $_FILES['upfile']['name']; $filename= str_replace(" ","_",$filename); $filename= str_replace(".","_",$filename); $filename = $filename.rand(1000,9999); PHP:
Got it fixed. I just change the line to $filename= str_replace(array(" ","."),"_",$filename); PHP: Stupid me. Thanks!