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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filename variable points to temp file 1

Status
Not open for further replies.

GeckoNZ

IS-IT--Management
Jul 23, 2001
31
Hi, I am trying to select a file from a form and then pass this filename to another function for processing. The the filename seems to end up as something like ... /tmp/php123XYZ

snippets of code :
(from the form)

echo " <form method=\"post\" ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\">";
echo " <input type=\"file\" name=\"LoadFile\" size=20 maxlength=50>";
echo " </form>";

..and something as simple as :

echo "file is : $LoadFile <br>";//for debugging

displays this /tmp/php123XYZ filename rather than that selected.

Thanks ...Geoff
 
Thanks for the link, it has helped me make some progress. I am able to get the filename from the file upload array $_FILES['LoadFile']['name'] but this is just the filename, not the full path name. Any idea how I can get the Directory element of the full path, it doesn't seem to be an element of the $_FILES array. So I still have difficulty in using this to pass the filename to other functions.

thanks
 
Get what full path name?

$_FILES['LoadFile']['tmp_name'] holds the full path and filename of where the temporary file resides.

The full path of the file, relative to the filesystem of the uploading workstation is meaningless. You're not uploading a chunk of your harddrive, just a file.

The full path to the directory to where you will move the file is arbitrary, based on your needs and current directory structure.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I guess that my real problem is in trying to pass the filename twice, i.e. to one function and then another. First get the filename thru the form with an input type of "file" so that I get the ability to browse the local file system. I pass the filename to a function that checks the file format and size and compares the number of records to the number of database rows in a table. The file I am uploading is a .CSV file for loading into a database table.

This first function displays information about the load file and the datbase table that it is to be loaded into, along with an "OK to proceed yes/no" form.

If the user says YES then I want to pass the filename to another function which loads it into the database. However, by this time the temp filename would appear to be no longer valid. Hence my desire to pass the original full path name to the second function.

thanks
 
Move the submitted file to a permanent location and set a session variable which stores that location. When the user submits the second form, (assuming the user submits a "yes") your script can retrieve the location from the session and process the file.

I recommend that you continue to use the temporary filename assinged by PHP when you move the file. You reduce the chance of collisions in filenames that way.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir214. I now have it all working beautifully thanks to you pointing me in the right direction. [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top