Solved

Two simple php questions

Posted on 2006-11-01
8
191 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 250 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 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 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