file uploading

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

file uploading

Post by chris12295 »

is there anyway to upload a file using PHP and name it what i want then ad the path to a database?
Peter
Forum Commoner
Posts: 28
Joined: Mon Jun 10, 2002 12:40 am
Location: Brisbane, Australia

Post 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. ;)
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post 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?
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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) &#123;
  $file = basename($filename);
  $tmp_upload_path = "c:\\apache\\htdocs\\tmp&quote;;
  $new_file_name = "c:\\apache\\upload&quote;.$newname;
  if (!copy($tmp_upload_path.$file, $new_file_name)) echo "failed to copy file<br>\n";
  return;
&#125;
?>
Hope that's what you need!
Post Reply