Solved

Two simple php questions

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
How do I speed up this PDO query 4 38
Get data from two MySQL tables 6 62
Considerations PHP using multiple locations 9 32
replacate wordpress websites 3 19
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to dynamically set the form action using jQuery.

738 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