?
Solved

Two simple php questions

Posted on 2006-11-01
8
Medium Priority
?
193 Views
Last Modified: 2006-12-28
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
0
Comment
Question by:frontpor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 1000 total points
ID: 17853267
Hi,

For your first question if you have that many simultanious people trying to upload you may have conflicts.  You could get around this by trying to add the current time to a database - and if it is successfully added you can use that as the file name, otherwise you try again until a unique time is generated.  Alternativley you could append the user's name or another id to the file meaning that you should not get duplicates.

For the second option if you use the $_SESSION array (started with session_start() ) this stores information for the person who is logged in.  If you wanted to track who was online you would need to pass the information for each logged in / guest to a database or repository that you could then query when you load your pages.
0
 
LVL 6

Expert Comment

by:neorush
ID: 17855746

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;
0
 
LVL 6

Assisted Solution

by:neorush
neorush earned 1000 total points
ID: 17855758
oh and to answer the session question a little better:

<?PHP

//start save user data....
if(!isset($_SESSION)){
   session_start();
}

if(!isset($_SESSION["username"])){
   $_SESSION["username"] = 'CurrentUsername';
}

echo $_SESSION["username"];

?>

<?PHP

//if you just need to get the user data back ....
if(!isset($_SESSION)){
   session_start();
}
echo $_SESSION["username"];

?>
0
 

Author Comment

by:frontpor
ID: 17856804
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?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 18057882
I think there should be a split betwen neorush and myself
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question