File Upload Values

I asked this question before but I was not very specific. I am working on a 2 page form. I need to have a file upload on the first page. I need to pass the file upload values to the insert page. I am not sure what approach to take. I have tried sessions but had no luck.

Here is a simplified version of my code.

Page 1:

Page 2:

Page 3:

<?php $uploadDir = 'upload/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } include 'includes/config.php'; include 'includes/opendb.php'; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "INSERT INTO contacts (first, name, size, type, path ) ". "VALUES ('$first', '$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); include 'includes/closedb.php'; echo "
Files uploaded
"; } ?>

Need to get the upload values from Page1 - Page3

Thank you in advance,


Once the file is uploaded on page one you need to do something with it. Not just the details but the file itself. During the upload, the file is stored in a temporary location, if you don’t do something with it, it will be lost on the next page.

I suggest you copy the file from the upload temporary location to another location (of your choosing) on the system, pass THOSE details to the final page and then use the system file management commands to do the processing you need.

You need to do the following on page 2 instead of page 3:

$uploadDir = ‘upload/’;

$fileName = $_FILES[‘userfile’][‘name’];
$tmpName = $_FILES[‘userfile’][‘tmp_name’];
$fileSize = $_FILES[‘userfile’][‘size’];
$fileType = $_FILES[‘userfile’][‘type’];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo “Error uploading file”;

Also, page 1’s form does not have an action attribute ;)

Sponsor our Newsletter | Privacy Policy | Terms of Service