Stop overwriting of user uploaded files if file name exists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

I got a problem with that code.. Even if there isnt a file on my server with the same name as the files that i want to upload.. it still gives me that error message "echo "<b>The file $imagefile chose to upload has the same name as a file on our server. Please rename it.</b>";"
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

I'm thinking you may want to just do hidden fields..

Code: Select all

<html><FORM enctype="multipart/form-data" ACTION="http://naild.com/localmm/modules.php?name=Band_Submit&file=upload" METHOD="POST"> 
<input name="band_name" type="hidden" id="band_name" value="<?php echo $bandname;?>">
<input name="description" type="hidden" id="description" value="<?php echo $description;?>">
<input name="history" type="hidden" id="history" value="<?php echo $history;?>">
<input name="influences" type="hidden" id="influences" value="<?php echo $influences;?>">
<input name="genra" type="hidden" id="genra" value="<?php echo $genra;?>">
<input name="email" type="hidden" id="email" value="<?php echo $email;?>">
<input name="website" type="hidden" id="website" value="<?php echo $website;?>">

   Upload files:<BR> 
    <i>Click Browse then browse to your file</i><br> 
   <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="200000" /> 
   Image File: (200 kb max)<br> 
   <INPUT TYPE="FILE" NAME="imagefile" SIZE="50">&nbsp <i>(IF you do select an image file or mp3 file to upload, UPLOAD TIMES MAY VARY. The page will appear to be loading, but thats the upload in progress)</i><BR> 
   <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="6000000" /> 
   Mp3/.avi/.mpg/.mpeg/.zip File: (6MB max)<br> 
   <INPUT TYPE="FILE" NAME="mp3file"  SIZE="50"><BR> 
   <INPUT TYPE="submit" name="submit" value="submit"><BR> 
</form></html>
i'd suggest putting something this in a separate file, then including it on the line just before your "exit()" function.

any opinions?
Last edited by phuts on Sun Feb 29, 2004 7:26 pm, edited 3 times in total.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

I'll Try that. But do you have any thoughts on why im getting that error message even when i upload a file that doesnt exist on my server.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

"There is already a file called on our server. Please rename this file.

Click the Back button and RE-SUBMIT. "

Thats the message i get when i try to upload an image. There is no image with the same file name as the one i tried uploading either.. Notice that $imagefile didnt echo anything.
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

hmmm.. like I said, i'm not sure if that code with the if( file_exists... line is correct.. anyone?

oh and typo in my previous post. $SERVER['PHP_SELF'] should be $_SERVER['PHP_SELF'] also, if you do an include (as opposed to simply inserting the code into the original file) replace the "$_SERVER['PHP_SELF"]" with the address of the upload script.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

Ok
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

sorry mikegotnaild, I'm not exactly what you'd call an expert when it comes to things outside of my own site. Hopefully some php god will come along and help us figure this out.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

:) Well there are some very smart people here.
phuts
Forum Newbie
Posts: 15
Joined: Thu Feb 19, 2004 12:29 am
Location: Ohio, USA

Post by phuts »

mikegotnaild wrote::) Well there are some very smart people here.
i'd wait for one of them.. heh
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

LoL thats what i spend the majority of my time doing on here.
Post Reply