Connecting Tech Pros Worldwide Help | Site Map

file upload

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:52 PM
Mosher
Guest
 
Posts: n/a
Default file upload

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>



  #2  
Old July 17th, 2005, 12:52 PM
Alvaro G Vicario
Guest
 
Posts: n/a
Default 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
--
  #3  
Old July 17th, 2005, 12:52 PM
Mosher
Guest
 
Posts: n/a
Default 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]


  #4  
Old July 17th, 2005, 12:52 PM
Mosher
Guest
 
Posts: n/a
Default 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]


  #5  
Old July 17th, 2005, 12:52 PM
Malcolm Dew-Jones
Guest
 
Posts: n/a
Default 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.
  #6  
Old July 17th, 2005, 12:52 PM
madmaster
Guest
 
Posts: n/a
Default 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

  #7  
Old July 17th, 2005, 12:53 PM
MsKitty
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.