»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 11-20-2003, 10:41 PM   #1 (permalink)
Registered User
 
Join Date: Oct 2003
Posts: 4
laowensjr is on a distinguished road
UPLOAD.PHP: Avoiding Filename Overwrites

THANK YOU IN ADVANCE

Here's the code I am using to upload the files.

<!--- PHP Portion Named uploads.php --->
<?php $updir = images;
if(!file_exists("$updir/$pic_name"))
{ copy($pic, "$updir" . "/" . $pic_name); }
else { echo "File already exists!"; } ?>
------------------------------------------------------------
This works Perfect, but the only thing is, If I have two users come and upload files which are named the same it will echo file already exists.

So PART 2, To solve this problem I would like to append a unique identifier like a user name. The form portion code which is named upload.html is:
----------------------------------------------------
<form enctype="multipart/form-data" action="http://www.mydomain.us/members/upload.php" method="post"> <input name="pic" type="file" size="20"></td> <input type="submit" value="Upload" name="upload">

-------------------------------------------------

So MY QUESTION:
How TO and IS IT POSSIBLE to add a form field in this same form above but make it username and when the user clicks on upload it will upload the image but add the username they entered into the form so such instead of when they upload arrow.gif it will be username_arrow.gif

Then Give us a way to call the same file they uploaded in the upload.html file in a page called my items.html

------------------------------------IDEA of what I am Trying to Do-----
I have a domain and have members in that domain. So the members website address is mydomain.com/theirusername

Now I added a image folder in the member folder so the form sends the image to the one folder that all my members share.
The reason why they are uploading images is for their Products Page.
The Products page will have THEIR image with product Description, and Price. I want their image to be called and displayed on this page. I would like to put something like

<?=$row['product']?>

for the image and ONLY the owner's image appears.

laowensjr is offline   Reply With Quote
Old 11-24-2003, 11:28 AM   #2 (permalink)
Registered User
 
drizzle's Avatar
 
Join Date: Oct 2001
Location: Louisiana, USA
Posts: 170
drizzle is on a distinguished road
Send a message via ICQ to drizzle Send a message via Yahoo to drizzle
PHP Code:
$_FILES['uploadedfile']['name'] = $username "_" $_FILES['uploadedfile']['name']); 
or
PHP Code:
$pic_name $username "_" $pic_name
Of course you'd need to swap out the variable $username with whatever variable you have for the members name. Another way to handle this would be to use a time stamp on the front of the filename. For accessing it later, probably the best thing to do would be to have the image name written to a db table and then use that to later call up the correct image.
drizzle is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 01:28 AM.