Link to home
Start Free TrialLog in
Avatar of frontpor
frontpor

asked on

Two simple php questions

Hello,
      i have two simple php questions. 1) I am uploading images and rename each image file to numbers by using time () function.. images name become like this 1162411085.jpg... my question is that what if 100 people are trying to upload files simultaneously... will this cause to upload error? i think php server is multi threaded so it can take many requests at once.

second question.. i am not quite professional in php.. just switched to php.. i want to track members and guests online on the website.. in asp there is an object Application where we store this kind of information in global.asa.. is there anything similiar in php too?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neorush
neorush


You could very well have some problems, as two iamges could be saved in the same second......just use microseconds....

$micro_time = substr(microtime(), 2, 6);
$filename = time().'.'.$micro_time.'.jpg';
echo $filename;

I'll admit this could under a very odd circumstance this could still be a problem. So you could do something like use an md5hash of the user (orginal) filename, plus this time thing....that should make it so there isn't a problem for sure

$filename = md5($_FILES["form_file_name"]["name"]);
$micro_time = substr(microtime(), 2, 6);
$filename = $filename.'.'.time().'.'.$micro_time.'.jpg';
echo $filename;
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of frontpor

ASKER

neorush dont you think this will be a very long name?
$filename = md5($_FILES["form_file_name"]["name"]);
$micro_time = substr(microtime(), 2, 6);
$filename = $filename.'.'.time().'.'.$micro_time.'.jpg';
echo $filename;

i think it would be best to attach id with microsecond.. id is always unique..

my second question was how will get online members and guests number.. when my site starts i start a session.. do i need to add a counter?
I think there should be a split betwen neorush and myself