User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,973 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,166 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

File Upload Variables

Join Date: May 2008
Posts: 6
Reputation: 2xldesign is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
2xldesign 2xldesign is offline Offline
Newbie Poster

File Upload Variables

  #1  
May 11th, 2008
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:
  1. <form method="post" enctype="multipart/form-data">
  2. <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
  3. <input name="userfile" type="file" id="userfile">
  4. <input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
  5. </form>

Page 2:
  1. <form action="insert.php" method="post">
  2. <input type="text" name="first" id="first" />
  3. <input type="submit" name="button" id="button" value="Submit" />
  4. </form>

Page 3:
  1. <?php
  2. $uploadDir = 'upload/';
  3.  
  4. if(isset($_POST['upload']))
  5. {
  6. $fileName = $_FILES['userfile']['name'];
  7. $tmpName = $_FILES['userfile']['tmp_name'];
  8. $fileSize = $_FILES['userfile']['size'];
  9. $fileType = $_FILES['userfile']['type'];
  10. $filePath = $uploadDir . $fileName;
  11. $result = move_uploaded_file($tmpName, $filePath);
  12. if (!$result) {
  13. echo "Error uploading file";
  14. exit;
  15. }
  16.  
  17. include 'includes/config.php';
  18. include 'includes/opendb.php';
  19. if(!get_magic_quotes_gpc())
  20. {
  21. $fileName = addslashes($fileName);
  22. $filePath = addslashes($filePath);
  23. }
  24. $query = "INSERT INTO contacts (first, name, size, type, path ) ".
  25. "VALUES ('$first', '$fileName', '$fileSize', '$fileType', '$filePath')";
  26. mysql_query($query) or die('Error, query failed : ' . mysql_error());
  27. include 'includes/closedb.php';
  28.  
  29. echo "<br>Files uploaded<br>";
  30. }
  31. ?>

Need to get the upload values from Page1 - Page3

Thank you in advance,

Scott
Last edited by peter_budo : May 11th, 2008 at 12:58 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 9:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC