Here's what I use. It is for multiple files. It has some bugs (for instance, if it errors out it still reports success) so if you fix them, I'd appreciate you sending me the fix. I rename the files as they come in with this script in case you're confused by the rename....
Directory names have been changed to protect the innocent. ------------------ if ( isset ( $files ) ) { //send an email to the webmaster if someone hits this area MAIL( "[EMAIL PROTECTED]", "CC Resolution Uploads Attempted", "From: $email\nX-Mailer: PHP/" . phpversion()); for ( $i=0 ; file_exists ( $files[$i] ) ; $i++ ) { echo "Trying to upload " . $files_name[$i] . "...<br />\n"; // if the file is too big, don't accept it (200K) if ( $files_size[$i] > 200000 ) { echo "The file, $result_name ($file_size bytes), is too big. Files that large are too big for this particular use. Possible attack dropped. Please contact $webmaster if you receive this message.<br />\n"; } // if $result_name isn't empty, try to copy the file elseif ( eregi ( "([0-9]{1,3})\-([0-9]{1,3})([A-Za-z]?)([a-z0-9 ,.]*).(doc|rtf)" , $files_name[$i] , $newres_name ) ) { echo "ERROR CHECK: Good Name!<br />\n"; $newfilename = $newres_name[1] . '-' . $newres_name[2] . $newres_name[3] . "." . $newres_name[5]; if ( !file_exists ( $newfilename ) ) { // copy the file to a directory or // print an error message // NOTE! if you're on a Windows machine, // use Windows pathnames, like so: // copy("$img1", "C:\\some\\directory\\path\\$img1_name"); copy("$files[$i]", "D:\\foo\\bar\\fbarred\\$files_name[$i]") or die("Couldn't copy the file!"); //rename the file rename("D:/foo/bar/fbarred/" . $files_name[$i], "D:/foo/bar/fbarred/" . $newfilename); ?> <H2>SUCCESS!</H2> <P><B>You sent:</B> <? echo "$files_name[$i]"; ?>, a <? echo "$files_size[$i]"; ?> byte file with a mime type of <? echo "$files_type[$i]"; ?>.<br /> It has been renamed <B><? echo "$newfilename"; ?></B>.</p><P> </P><P> </P> <?PHP } else { //file as renamed already exists //GOTTA DO SOMETHING HERE TO ALLOW A REPLACE echo "<H3>That file already exists!</H3><br /><br />\n"; } } else { //file didn't fit eregi check echo "I don't understand that file name or no input file specified."; } } } /* *********************************** *** MAIN ELSE - form to enter file*** ************************************ */ else { ?> <form enctype="multipart/form-data" method="post" action="<?echo $PHP_SELF?>"> <P><strong>File to Upload:</strong><P> <?PHP for ($i=1 ; $i<=20 ; $i++ ) { ?> <P>File: <input type="file" name="files[]" size="60"></p> <?PHP } ?> <P> </P> <P><input type="submit" name="submit" value="Upload Results"></p> <?PHP } --------------------- John Asendorf - [EMAIL PROTECTED] Web Applications Developer http://www.lcounty.com - NEW FEATURES ADDED DAILY! Licking County, Ohio, USA 740-349-3631 Nullum magnum ingenium sine mixtura dementiae fuit > -----Original Message----- > From: Andrew.Martin [mailto:[EMAIL PROTECTED]] > Sent: Monday, October 01, 2001 7:07 AM > To: [EMAIL PROTECTED] > Subject: [PHP-WIN] copying files...? > > > I want to copy a file from a users PC (via a form) to a > specific folder on > the webserver and store the file name in the Database. > I have tried to use the copy($string, $path) function but I > keep getting > errors. > > Does anyone know a simplat solution for this? Do I have to > copy the contents > of the file to a temp file on the server first? If so how? > Or is there another function to do what I require? > > thanks, > > Andrew > -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]