Page 1 of 1
file uploading
Posted: Thu Jun 13, 2002 7:04 pm
by chris12295
is there anyway to upload a file using PHP and name it what i want then ad the path to a database?
Posted: Thu Jun 13, 2002 8:57 pm
by Peter
You can use PHP HTTP Post files uploading (more info
here) and then store $HTTP_POST_FILES['userfile']['tmp_name'] (unless you copy() the file) in the database.

Posted: Thu Jun 13, 2002 10:57 pm
by chris12295
lets just say i want to get a bunch of information and upload an image file, and insert the information and (ex)1/1.gif(for pic field) into a database.
How could i upload the file and put the 1/1.gif path with all the other information into the database?
Posted: Thu Jun 13, 2002 11:06 pm
by Jim
Create the upload by using:
<input type="file" name="filename">
and create another field like this:
<input type="text" name="newname">.
Change the temp upload path to your temp folder, and your new name path to the place you want the file to be.
Just-like-this:
Code: Select all
<?php
function do_upload($filename,$newname) {
$file = basename($filename);
$tmp_upload_path = "c:\\apache\\htdocs\\tmp"e;;
$new_file_name = "c:\\apache\\upload"e;.$newname;
if (!copy($tmp_upload_path.$file, $new_file_name)) echo "failed to copy file<br>\n";
return;
}
?>
Hope that's what you need!