RE: [PHP] ie problem with file upload

From: Date: Wed, 09 Aug 2000 17:16:49 +0000
Subject: RE: [PHP] ie problem with file upload
Groups: php.general 
Request: Send a blank email to php-general+get-10962@lists.php.net to get a copy of this message
Let's assume that the name of the file uploaded (that is, the name that the file had on the user's computer) is in $old_name, and the name of the temporary file (on the server) is $temp_name, and the directory that you want to store all uploaded files to is $file_dir. You'd do the following to store the uploaded file to file_dir: $clean_name = clean_path($old_name); $success = copy ($temp_file, "$file_dir/$clean_name"); You'd probably want to add in error checking and logic to deal with multiple files with the same name. To handle multiple files, I create directories under $file_dir such as 1/, 2/, and 3/ to hold the files. If the file already exists in $file_dir/1, I check $file_dir/2, etc. --Bruce Bruce Christensen Intel Corporation brucex.r.christensen@intel.com -----Original Message----- From: Kevin Beckford [mailto:kbeckford@bigorbit.com] Sent: Wednesday, August 09, 2000 9:32 AM To: Christensen, BruceX R Subject: Re: [PHP] ie problem with file upload hey - where do you apply this function? If I have a file called up_file, do I appy this function to it and then copy it? Or do I apply it to up_file_name? ----- Original Message ----- From: Christensen, BruceX R <brucex.r.christensen@intel.com> To: 'Kevin Beckford' <kbeckford@bigorbit.com>; GPHP <php-general@lists.php.net> Sent: Tuesday, August 08, 2000 5:15 PM Subject: RE: [PHP] ie problem with file upload > Here's what I do to get a nice filename from an uploaded file: > > /////////////////////////////////////////////////////////// > // clean_path: strip path information and illegal ///////// > // characters from a filename ///////////////////////////// > /////////////////////////////////////////////////////////// > /* > Returns a legal filename w/o path info. > */ > function clean_path ($path) { > return ereg_replace("[:*?\"<>|]", "", > basename(str_replace('\\', > '/', $path))); > } > > Note that this will only give you dogfood.txt, not blabla\woogy\dogfood.txt > or something similar. Because it only gives you the filename, you can put > it in whatever directory you want, without having to worry about creating > the extra directories specified (which you usually don't want, anyway). > > (It's probably better to use an ereg() to match valid characters instead of > the ereg_replace() that I used to get rid of illegal characters, but this is > an intranet environment, where the name of the game is flexibility and > development time, not security.) > > --Bruce > > Bruce Christensen > Intel Corporation > brucex.r.christensen@intel.com > > > -----Original Message----- > From: Kevin Beckford [mailto:kbeckford@bigorbit.com] > Sent: Tuesday, August 08, 2000 2:07 PM > To: GPHP > Subject: [PHP] ie problem with file upload > > > When I upload a file with netscape - everything is fine and dandy, When I do > the same with IE, I get a filename in the form > C:\\blabla\\woogy\\dogfood.txt > What causes this, and what is the solution? > ______________________________________ > Kevin Beckford > Programmer > Big Orbit - Specializing in new media for youth > www: http://www.bigorbit.com > email: kbeckford@bigorbit.com > [t] 416.516.0705 > [f] 416.516.9256 > > "Intelligence is a tool used achieve goals, however goals are not always > chosen > wisely..." > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#10962) next »