Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file upload and adding name to dbase 1

Status
Not open for further replies.

deecee

Technical User
Aug 25, 2001
1,678
0
0
US
How can i pull the name of a file that a user is uploading and add that name to a database

lets say i have a 2 field form -- file and file id -- each salesrep has to give a file a file id that a client will enter to download the file. i can get the file uploaded but how do i pull the filename and add that into a 3 column mysql dbase? Only zip files will be allowed btw. and the files are going into folder 'files'

so the filepath would be 'files/filename.zip' I also want to check for same name files before upload and should be able to figure that out. but my main inquiry is how do i get the filename only from the browse textbox into the dbase prceeded of course by 'files/'

thanks

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
perhaps you can also insert a field in the database first and rename your file to the autokey returned by mysql ;)
 
well the point of this is that sales reps have large piles of info to get to a client and email rejects cuz of size. so they upload file and tell client go to


there they enter the fileid and the file will download.

so if i rename the file to match the autokey how does the salesrep know the new filename without me getting back to them -- im trying to avoid this --

sleip -- how does $_FILES help me -- i barely understood the definition (probably didnt) -- but I am assuming that that if i pass the fileinfo from the form to another page $_files will be the filename and not the whole path in the form field?

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
deecee,

below is a script I use for doing just that, a simple html form posts the data to this form that does the work. Note $page and $fext are my variables.

The line -

substr(&quot;$newfile&quot;, 38);

strips the /home/extrabucc/public_html/schedules/ so that just the filename is inputed into the database, which makes it easier to manipulate later.

HTH

Nige.

~~~~~~~~~~~~~~~~~~~~Script below~~~~~~~~~~~~~~~~~~~~~~~~~~

$numoffile = 1;
$file_dir = &quot;/home/extrabucc/public_html/schedules/&quot;;
if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!=&quot;&quot;) {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$j++;
}
}
}
$file = substr(&quot;$newfile&quot;, 38);
$db = mysql_connect(&quot;host&quot;, &quot;user&quot;, &quot;password&quot;);
mysql_select_db(&quot;databasename&quot;, $db);


$sql = &quot;INSERT INTO $page (sched_id, file) VALUES ('$sched_id','$file')&quot;;

$result = mysql_query($sql);

echo &quot;<p><center>Schedule uploaded <a href=\&quot;/showsec/$fext\&quot;>Click Here</a> to proceed</p></center>&quot;;



?>
 
thanks man looks like what i need -- now i just need to implement

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top