I am currently writing a mobile application using phonegap. One of the few functions that I would like to get from this application is the ability to capture an image and upload it to a remote server ...
I currently have an image capture and upload / email part that works fine with compiled apk ... but in my php I currently call the image "image [insert random number from 10 to 20] ... Problem here is what numbers can be repeated and images can be overwritten ... I read and thought about just using rand () and picking a random number from 0 to getrandmax (), but I feel like I can have the same the probability of overwriting the file ... I need the image to be uploaded to the server with a unique name every time, no matter what ... so php script will check to see that the server already has and writes / uploads an image with a unique name ...
any ideas other than "rand ()"?
I also thought about possibly naming each image ... img + date + time + random 5 characters that will contain letters and numbers ... so if the image was taken using the application at 4:37 a.m. March 20, 2013, the image will be called something like "img_03-20-13_4-37am_e4r29.jpg" when uploading to the server ... I think this might work ... (if this is not the best way), but I quite new in php and didn't understand how to write something like that ...
my php looks like this:
print_r($_FILES); $new_image_name = "image".rand(10, 20).".jpg"; move_uploaded_file($_FILES["file"]["tmp_name"], "/home/virtual/domain.com/public_html/upload/".$new_image_name);
Any help is appreciated ... Thanks in advance! Also, please let me know if there is any additional information that I can ignore ...
source share