Hi all, this might be more of an html question but I think it can be done in
PHP, so I will ask here.
I have an html form that allows for .pdf file uploads. This script will
serve two functions 1) upload a .pdf file to a specific directory on the web
server and 2) create an entry into the db that includes the name of the file
just uploaded. I want to have another web page that will dynamically list
all of the names of the files uploaded as clickable hyperlinks so they can
view those .pdf files.
I have the file upload code working just fine, but the name that gets
written to the database as something like: "/tmp/phpTg2toF", which is not
the name of the file. How can I "get" the name of the file that I upload so
that it can be written into the db as a file name? Anyone have ideas? Thanks
in advance. Here is my code:
<html>
<head>
<title>Upload </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<form action="thisfil e.php" method="post" ENCTYPE="multip art/form-data">
<body bgcolor="#fffff f" text="#000000">
<?{
if ($Upload) {
if (!copy($file, "../TargetDir/$file_name")) {
echo "Problem uploading .pdf file...please try
again.<br><br>< br><br><br>";
exit;
} else {
$result = mysql_query("in sert into db values ('$id', '$name')");
if (!$result) {
echo "<br><br>Th ere was a problem adding the .pdf - please submit
later.";
}?>
<input type="file" size=40 name="file"><br >
<input type="hidden" name="MAX_FILE_ SIZE" value="100000">
<input type="submit" name=Upload value="Upload">
<?}?>
</form></body></html>
PHP, so I will ask here.
I have an html form that allows for .pdf file uploads. This script will
serve two functions 1) upload a .pdf file to a specific directory on the web
server and 2) create an entry into the db that includes the name of the file
just uploaded. I want to have another web page that will dynamically list
all of the names of the files uploaded as clickable hyperlinks so they can
view those .pdf files.
I have the file upload code working just fine, but the name that gets
written to the database as something like: "/tmp/phpTg2toF", which is not
the name of the file. How can I "get" the name of the file that I upload so
that it can be written into the db as a file name? Anyone have ideas? Thanks
in advance. Here is my code:
<html>
<head>
<title>Upload </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<form action="thisfil e.php" method="post" ENCTYPE="multip art/form-data">
<body bgcolor="#fffff f" text="#000000">
<?{
if ($Upload) {
if (!copy($file, "../TargetDir/$file_name")) {
echo "Problem uploading .pdf file...please try
again.<br><br>< br><br><br>";
exit;
} else {
$result = mysql_query("in sert into db values ('$id', '$name')");
if (!$result) {
echo "<br><br>Th ere was a problem adding the .pdf - please submit
later.";
}?>
<input type="file" size=40 name="file"><br >
<input type="hidden" name="MAX_FILE_ SIZE" value="100000">
<input type="submit" name=Upload value="Upload">
<?}?>
</form></body></html>
Comment