Solved

Two simple php questions

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now