Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* and then Thomas Edison Jr. declared
 Hi,
 
 If i have a filename room.jpg in my Upload
 Directory, and someone else comes and uploads a file
 by the same name, the previous room.jpg is
 overwritten by the new one. Any suggestions?

Well, I presume that you would like for this *not* to happen right?

if so, just add a if(file_exist($img)) { change name of img.

I expect you could add an 1 to the end or better still, have the user
choose another name?

- -- 
Nick Wilson //  www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE83PEnHpvrrTa6L5oRApJlAJ9n3/jsPvej8U1DwjDQnED7wwp4FQCgjjGh
SO2IqQydOwy9zA0Q7TCd9no=
=xxgQ
-END PGP SIGNATURE-

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

Hmm...

Tried it, and this doesn't sound too good :

Fatal error: Call to undefined function: file_exist()
in d:\apache
group\apache\htdocs\mjimm\mjpals_added.php on line 37

Basically this is what i added in the appropriate
place :

if(file_exist($img1_name)) {
$img1_name = $img1_name+n;
}

And thanks a lot..

Thus Spake T. Edison Jr. !!

--- Nick Wilson [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 
 * and then Thomas Edison Jr. declared
  Hi,
  
  If i have a filename room.jpg in my Upload
  Directory, and someone else comes and uploads a
 file
  by the same name, the previous room.jpg is
  overwritten by the new one. Any suggestions?
 
 Well, I presume that you would like for this *not*
 to happen right?
 
 if so, just add a if(file_exist($img)) { change name
 of img.
 
 I expect you could add an 1 to the end or better
 still, have the user
 choose another name?
 
 - -- 
 Nick Wilson //  www.explodingnet.com
 
 
 
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.0.6 (GNU/Linux)
 

iD8DBQE83PEnHpvrrTa6L5oRApJlAJ9n3/jsPvej8U1DwjDQnED7wwp4FQCgjjGh
 SO2IqQydOwy9zA0Q7TCd9no=
 =xxgQ
 -END PGP SIGNATURE-
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* and then Thomas Edison Jr. declared
 Hmm...
 
 Tried it, and this doesn't sound too good :
 
 Fatal error: Call to undefined function: file_exist()
 in d:\apache
 group\apache\htdocs\mjimm\mjpals_added.php on line 37

Sorry, it was a typo: Should be file_exists() 
Check it out in the manual: 
http://www.php.net/manual/en/function.file-exists.php

- -- 
Nick Wilson //  www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE83Pa4HpvrrTa6L5oRAlOuAJ4meFuxunwzNIIfYnXxNAoqQuhjwwCfSwn9
LuCbATQVtzhllC7YbV9cML0=
=PkOX
-END PGP SIGNATURE-

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

Glory  Power!

I'm using the following code now... the Error is gone,
but it's still overwriting the old file. It's not
changing the name.. not doing anything, just uploading
this new file and replacing the old one.. 


?php

$db = mysql_connect(localhost,use,pwd);
mysql_select_db(dbname,$db);

if ($img1_name != ) {
$pic = yes; 
}
else {
$pic = no;
}

$date = date(l dS of F Y h:i:s A);

// if $img_name isn't empty, try to copy the file
if (($img1_name != ) and ($img1_size = 256000)
and ($img1_type == image/pjpeg) or ($img1_type ==
image/jpeg)) {
if(file_exists($img1_name)) {
$img1_name = n+$img1_name;
}
$sql = INSERT INTO mjpals
(name,age,gender,country,email,date,profile,looking,pic_name,pic)
VALUES
('$name','$age','$gender','$country','$email','$date','$profile','$looking','$img1_name','$pic');
$result = mysql_query($sql) or die(You made a
mistake, please go back and try again);
copy($img1, mjpalpics/$img1_name)
or Die (Could not do);
} 
elseif (($img1_name == ) and ($img1_size  256000)
and ($img1_type != image/pjpeg) or ($img1_type !=
image/jpeg)) {
$sql = INSERT INTO mjpals
(name,age,gender,country,email,date,profile,looking,pic_name,pic)
VALUES
('$name','$age','$gender','$country','$email','$date','$profile','$looking','','no');
$result = mysql_query($sql) or die(You made a
mistake, please go back and try again);
}
?

Thank you for adding you details. The following has
been added to the Database :brbr
big
?php

$profile = stripslashes($profile);
$looking = stripslashes($looking);

echo (
Name : $namebr
Age : $agebr
Gender : $genderbr
Country : $countrybr
Email : $emailbr
Your Profile : $profilebr
You are looking for : $lookingbr
);

if (($img1_size = 256000) and ($img1_type ==
image/pjpeg) or ($img1_type == image/jpeg)) {

echo 
Your Photo : iName - $img1_name | Size - $img1_size
| MIME Type - $img1_type/i br
; 

}
else {
echo No photograph uploaded, or wrong Type/Size
photograph;
}
?

=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* and then Thomas Edison Jr. declared
 Glory  Power!
 
 I'm using the following code now... the Error is gone,
 but it's still overwriting the old file. It's not
 changing the name.. not doing anything, just uploading
 this new file and replacing the old one.. 
 

Well, I don't see any thing in your code that denotes the directory the
images are going in? The idea is to check if 'path/to/img/img.jpg'
exists and if so, name the upload img to something else. 

I also don't see anything in you php about the 'tmp_name' etc? are you 
sure you understand how to upload images? there is a very good section 
in the manual on file uploads. (i just learnt it myself for a project)
- -- 
Nick Wilson //  www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE83Pp5HpvrrTa6L5oRAhYDAJ4ibvcPhX55WJ3HTtiz3rT20qK5TACfaEJ5
LuJKsZCN8TFmUQJFIzVMM14=
=meFO
-END PGP SIGNATURE-

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

Glory!

 Well, I don't see any thing in your code that
 denotes the directory the images are going in?

What about this :

copy($img1, mjpalpics/$img1_name) or Die (Could
not do);

Sends the images to the mjpalpics Directory!


 'path/to/img/img.jpg'
 exists and if so, name the upload img to something
 else. 

Hmm... possibly when i say
if(file_exists($img1_name)), he's looking for the file
name in the Directory where the Images initially go..
but then since i copy them elsewhere, they won't be in
the initial place.. and so he overwrites while
copying..Possibly! Don't know for sure. 

T. Edison Jr.






=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* and then Thomas Edison Jr. declared
 Hmm... possibly when i say
 if(file_exists($img1_name)), he's looking for the file
 name in the Directory where the Images initially go..
 but then since i copy them elsewhere, they won't be in
 the initial place.. and so he overwrites while
 copying..Possibly! Don't know for sure. 

Well, check out the manual, you'll find good stuff there. and dot your
code with print($whatevers) to see whats going on.

- -- 
Nick Wilson // www.tioka.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE83Pz7HpvrrTa6L5oRAi87AJ0aqEBYw/ii3CiBjZ6h/oFlRseWuQCeKkTG
NA6OVtmTrVU841aLkqnZwFI=
=k4Rg
-END PGP SIGNATURE-

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

Well thanks a bunch!

--- Nick Wilson [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 
 * and then Thomas Edison Jr. declared
  Hmm... possibly when i say
  if(file_exists($img1_name)), he's looking for the
 file
  name in the Directory where the Images initially
 go..
  but then since i copy them elsewhere, they won't
 be in
  the initial place.. and so he overwrites while
  copying..Possibly! Don't know for sure. 
 
 Well, check out the manual, you'll find good stuff
 there. and dot your
 code with print($whatevers) to see whats going on.
 
 - -- 
 Nick Wilson // www.tioka.com
 
 
 
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.0.6 (GNU/Linux)
 

iD8DBQE83Pz7HpvrrTa6L5oRAi87AJ0aqEBYw/ii3CiBjZ6h/oFlRseWuQCeKkTG
 NA6OVtmTrVU841aLkqnZwFI=
 =k4Rg
 -END PGP SIGNATURE-
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Jason Wong

On Saturday 11 May 2002 19:05, Thomas Edison Jr. wrote:
 Glory!

  Well, I don't see any thing in your code that
  denotes the directory the images are going in?

 What about this :

 copy($img1, mjpalpics/$img1_name) or Die (Could
 not do);

 Sends the images to the mjpalpics Directory!

  'path/to/img/img.jpg'
  exists and if so, name the upload img to something
  else.

 Hmm... possibly when i say
 if(file_exists($img1_name)), he's looking for the file
 name in the Directory where the Images initially go..
 but then since i copy them elsewhere, they won't be in
 the initial place.. and so he overwrites while
 copying..Possibly! Don't know for sure.

Possibly. But one thing that is definitely a problem is:

  if(file_exists($img1_name)) {
$img1_name = n+$img1_name;
  }

should be:

  if(file_exists($img1_name)) {
$img1_name = n . $img1_name;
  }

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
I had the rare misfortune of being one of the first people to try and
implement a PL/1 compiler.
-- T. Cheatham
*/

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




RE: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread John Holmes

  copy($img1, mjpalpics/$img1_name) or Die (Could
  not do);
 
  Sends the images to the mjpalpics Directory!
 Possibly. But one thing that is definitely a problem is:
 
   if(file_exists($img1_name)) {
 $img1_name = n+$img1_name;
   }
 
 should be:
 
   if(file_exists($img1_name)) {
 $img1_name = n . $img1_name;
   }

Umm...wouldn't you want to use file_exists(mjpalpics/$img1_name)
instead? Otherwise you're not checking for it existing in the same place
you are copying it to...

---John Holmes...


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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Miguel Cruz

On Sat, 11 May 2002, Thomas Edison Jr. wrote:
 If i have a filename room.jpg in my Upload
 Directory, and someone else comes and uploads a file
 by the same name, the previous room.jpg is
 overwritten by the new one. Any suggestions?

In the long run, I think the best plan is to name your files after the 
unique database ID.

Store the names ('room.jpg') in the database.

If you expect getting more than a thousand files or so, split them into 
directories. If you use a numeric key, just take the last digit or two and 
use that for the directory (for instance, '4745' would go in '5/4745'). 

Then write a simple readfile script to process downloads (see today's 
thread about protecting downloads).

You can look in the database and construct URLs like:

  img src=image.php/4745/room.jpg

and your download script can look at the number to figure out which
directory it's in, and look at the file name to figure out the mime type
to send. The browser's happy because it thinks it's getting a file called
room.jpg no matter how many of them you have, the server is happy because
the files are spread nicely across a few directories, you're happy because
you got your work done, and I'm happy because you sent me a British
Airways gift certificate out in gratitude.

miguel


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




RE: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

WOOO.. i did not know this was possible :
file_exists(mjpalpics/$img1_name)

And this might actually solve the whole issue!! Let me
try this.. 

Thanks a BUNCH!
T. Edison Jr.


--- John Holmes [EMAIL PROTECTED] wrote:
   copy($img1, mjpalpics/$img1_name) or Die
 (Could
   not do);
  
   Sends the images to the mjpalpics Directory!
  Possibly. But one thing that is definitely a
 problem is:
  
if(file_exists($img1_name)) {
  $img1_name = n+$img1_name;
}
  
  should be:
  
if(file_exists($img1_name)) {
  $img1_name = n . $img1_name;
}
 
 Umm...wouldn't you want to use
 file_exists(mjpalpics/$img1_name)
 instead? Otherwise you're not checking for it
 existing in the same place
 you are copying it to...
 
 ---John Holmes...
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Thomas Edison Jr.

Hmm..

You gave me a lot to think about, and a whole lot of
work to do. I definately love your idea and logic, and
yes, it would make everyone happy.

well i guess by the time i figure the coding and
process out, i'll keep in mind to arrange for your
British Airways Gift Certificate too.

Glory!
T. Edison jr.

--- Miguel Cruz [EMAIL PROTECTED] wrote:
 On Sat, 11 May 2002, Thomas Edison Jr. wrote:
  If i have a filename room.jpg in my Upload
  Directory, and someone else comes and uploads a
 file
  by the same name, the previous room.jpg is
  overwritten by the new one. Any suggestions?
 
 In the long run, I think the best plan is to name
 your files after the 
 unique database ID.
 
 Store the names ('room.jpg') in the database.
 
 If you expect getting more than a thousand files or
 so, split them into 
 directories. If you use a numeric key, just take the
 last digit or two and 
 use that for the directory (for instance, '4745'
 would go in '5/4745'). 
 
 Then write a simple readfile script to process
 downloads (see today's 
 thread about protecting downloads).
 
 You can look in the database and construct URLs
 like:
 
   img src=image.php/4745/room.jpg
 
 and your download script can look at the number to
 figure out which
 directory it's in, and look at the file name to
 figure out the mime type
 to send. The browser's happy because it thinks it's
 getting a file called
 room.jpg no matter how many of them you have, the
 server is happy because
 the files are spread nicely across a few
 directories, you're happy because
 you got your work done, and I'm happy because you
 sent me a British
 Airways gift certificate out in gratitude.
 
 miguel
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


=
Rahul S. Johari (Director)
**
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : [EMAIL PROTECTED]
Tel : 91-4546512/4522124
***

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] Uploaded File OverWriting Old File

2002-05-11 Thread Jason Wong

On Sunday 12 May 2002 01:38, Thomas Edison Jr. wrote:
 WOOO.. i did not know this was possible :
 file_exists(mjpalpics/$img1_name)

 And this might actually solve the whole issue!! Let me
 try this..

You might find is_file() to be a 'more reliable' indicator because 
file_exists() works for both directories and files. Thus if for some reason 
$mg1_name was empty then your statement above would effectively be:

  file_exists(mjpalpics)

which, assuming that your directory always exists, would return true, which 
may not be what you want.

I was bitten by this 'feature' of file_exists() just today, had me stumped 
for a good hour or so.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
To avoid criticism, do nothing, say nothing, be nothing.
-- Elbert Hubbard
*/

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