Connecting Tech Pros Worldwide Help | Site Map

file upload

Mosher
Guest
 
Posts: n/a
#1: Jul 17 '05
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="thisfile.php" method="post" ENCTYPE="multipart/form-data">
<body bgcolor="#ffffff" 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("insert into db values ('$id', '$name')");
if (!$result) {
echo "<br><br>There 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>


Alvaro G Vicario
Guest
 
Posts: n/a
#2: Jul 17 '05

re: file upload


*** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=blue]
> 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?[/color]

Sorry, I can't understand your code. But the name of the original file is
kept in the $_FILES array. View its contents using print_r() and then adapt
your code.



--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Mosher
Guest
 
Posts: n/a
#3: Jul 17 '05

re: file upload


Alvaro, thanks for the info. Can you point me to some information about the
$_FILES statement? I can't seem to find any info on it.

Thanks again,

Mosher

"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
message news:57tlbzavc30o.jlaqzfcgj5mm$.dlg@40tude.net...[color=blue]
> *** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=green]
>> 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?[/color]
>
> Sorry, I can't understand your code. But the name of the original file is
> kept in the $_FILES array. View its contents using print_r() and then
> adapt
> your code.
>
>
>
> --
> -- Álvaro G. Vicario - Burgos, Spain
> -- http://bits.demogracia.com - Mi sitio sobre programación web
> -- Don't e-mail me your questions, post them to the group
> --[/color]


Mosher
Guest
 
Posts: n/a
#4: Jul 17 '05

re: file upload


Alvaro, thanks so much for the info. I was able to get the original file
name by using: $HTTP_POST_FILES['file']['name']

Mosher

"Alvaro G Vicario" <alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote in
message news:57tlbzavc30o.jlaqzfcgj5mm$.dlg@40tude.net...[color=blue]
> *** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=green]
>> 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?[/color]
>
> Sorry, I can't understand your code. But the name of the original file is
> kept in the $_FILES array. View its contents using print_r() and then
> adapt
> your code.
>
>
>
> --
> -- Álvaro G. Vicario - Burgos, Spain
> -- http://bits.demogracia.com - Mi sitio sobre programación web
> -- Don't e-mail me your questions, post them to the group
> --[/color]


Malcolm Dew-Jones
Guest
 
Posts: n/a
#5: Jul 17 '05

re: file upload


Mosher (mosh_king@yahoo.com) wrote:
: Alvaro, thanks for the info. Can you point me to some information about the
: $_FILES statement? I can't seem to find any info on it.

That's odd, try google: php $_FILES

maybe that will have some info on it.


--

This space not for rent.
madmaster
Guest
 
Posts: n/a
#6: Jul 17 '05

re: file upload


Hi all.. here is the original manual topic for files upload and thought
It could be useful.

http://php.net/features.file-upload

MsKitty
Guest
 
Posts: n/a
#7: Jul 17 '05

re: file upload


Here is a function I wrote to move an uploaded file to where I want it
with the original file name which is $_FILES['userfile']['name'] -
the temp name is $_FILES['userfile']['tmp_name']



function file_upload(){
global $ourdir;
$uploadFile = $ourdir ."/". $_FILES['userfile']['name'];
if (file_exists($_FILES['userfile']['tmp_name'])) {

if (!move_uploaded_file($_FILES['userfile']['tmp_name'],
$uploadFile))
{
print "Problem with file upload - Here's some debugging
info:\n<pre>";
print_r($_FILES);
print "</pre>";
} else {
chmod($uploadFile, 0644);
}
}
}


Hope this helps (no flames about using an evil global variable please!
made sense in this app)

Kitty
http://OpenSkyWebDesign.com

Closed Thread