On Mon, October 9, 2006 6:22 am, Captain wrote:
> hi dude,
> actually, i am new to php. i am not understanding clearly. plz explain
> it
> clearly.

You can't do what you want.

More importantly, you should not even WANT to do what you want!

There are several reasons for this, and they are rather subtle, and
require a mind-shift in your thinking.

The first thing you MUST get used to is that the SERVER where your PHP
script lives is VERY far away, in all respects, from the CLIENT where
your user sits and the POPUP appears.

PHP can't be involved in the POPUP because it's nowhere near that
popup -- PHP spits out the HTML and Javascript and then PHP is *gone*

The second reason you do NOT want to do this is this:
Suppose you could even make it work -- Throw in some AJAX-y Web2.0
thingie that checked back to the server every 2 seconds to make sure I
put in a different filename.  Fine.

You *still* have a BIG PROBLEM in that you are, almost for sure,
dealing with a web application where ANOTHER user can upload the same
file name in between your check and when the upload is actually done:

Imagine 2 users working at the same time:
User 1                 User 2
Check A.txt: OK        Check A.txt: OK
Upload A.txt           Upload A.txt

As you can see, only one of the users is going to "win" this race --
when they each checked if the name was already taken, everything was
fine.  But once they upload, one of them will be "first" and get the
name, and the second will either overwrite the first, or it will get
rejected anyway.

So you might as well not try to do any of this until the user actually
uploads -- And you do NOT need to store their filename exactly as they
used it.  You can just add a digit to make it unique.  Or you can put
each user's files in their own directory to reduce conflicts.

There are many ways to "solve" this, but, ultimately, you have to
check the filename in such a way that you do NOT introduce a Race
Condition.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to