Connecting Tech Pros Worldwide Help | Site Map

file upload

  #1  
Old July 17th, 2005, 01:52 PM
Mosher
Guest
 
Posts: n/a
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, 01:52 PM
Alvaro G Vicario
Guest
 
Posts: n/a

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, 01:52 PM
Mosher
Guest
 
Posts: n/a

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, 01:52 PM
Mosher
Guest
 
Posts: n/a

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, 01:52 PM
Malcolm Dew-Jones
Guest
 
Posts: n/a

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, 01:52 PM
madmaster
Guest
 
Posts: n/a

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, 01:53 PM
MsKitty
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Upload shapper answers 3 February 12th, 2008 02:15 PM
The BEST "FREE" Pure ASP 10MB File Upload hotflash answers 2 January 30th, 2008 12:59 AM
probls with file upload script... pls help pbd22 answers 7 December 11th, 2006 05:29 PM
PHP File Upload Fails Vic Spainhower answers 6 December 4th, 2006 11:35 PM
Re basic file upload form Simon answers 15 July 17th, 2005 05:53 AM