943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1130
  • PHP RSS
Sep 1st, 2010
0

$_FILES empty

Expand Post »
I am trying to create a file upload form on a website and am getting the error:

Notice: Undefined index:

My code is:

php Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3.  
  4. if (isset($_GET['submitted'])){
  5. print_r($_FILES);
  6. $displayName = $_GET['displayName'];
  7. //file name is name of user who uploaded-date-time ie awestove-20100901-0800
  8. $fileName = $_GET['username']."-".date('Ymd-Hi');
  9. $origFileName = $_FILES['fileChooser']['name'];
  10. $ext = end(explode(".", $origFileName));
  11. $targetPath = "uploads/";
  12. $targetPath = $targetPath . $fileName . $ext;
  13. if(move_uploaded_file($_FILES['fileChooser']['tmp_name'], $targetPath)) {
  14. echo "The file ". basename( $_FILES['fileChooser']['name']).
  15. " has been uploaded";
  16. } else{
  17. echo "There was an error uploading the file, please try again!";
  18. }
  19.  
  20. }
  21. else {
  22. ?>
  23.  
  24. <form enctype='multipart/form-data' name="addFile" id="addFile" action="<?php echo $_SERVER['PHP_SELF']."?completed=true";?>"
  25. method="post" onSubmit="return checkInputErrors('addFile','ajax/addFile.php')">
  26. <div class='formContainer'>
  27. <div class='inputContainer'>
  28. <div class='label' id='displayNameLabel'>Name to Display:</div>
  29. <div class='textEntry'>
  30. <input type='text' name='displayName'/><br />
  31. </div>
  32. <div class='text'>
  33. <input type="hidden" name="username" value="<?php echo $_SESSION[$appId]['userId']?>" />
  34. </div>
  35. </div>
  36. <div class='inputContainer'>
  37. <div class='label' id='fileChooserLabel'>File to Upload:</div>
  38. <div class='textEntry'>
  39. <input name='fileChooser' id='fileChooser' type='file' size='40' /><br />
  40. </div>
  41. </div>
  42. <div class='inputContainer'>
  43. <div class='submitButton'>
  44. <input type='submit' name='submit' value='Submit' />
  45. </div>
  46. </div>
  47. </div>
  48. </form>
  49.  
  50. <?php
  51. }
  52. ?>

In my HTML form I have
PHP Syntax (Toggle Plain Text)
  1. <input name='fileChooser' id='fileChooser' type='file' size='40' /><br />

but in the php section it says that 'fileChooser' is an undefined Index. print_r and var_dump tell me that $_FILES is an empty array. I'm at a loss, any help?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
awestove is offline Offline
8 posts
since Aug 2009
Sep 1st, 2010
0
Re: $_FILES empty
Works good for me...
I have noticed $appId variable. Maybe you are using it for a Facebook application?
Reputation Points: 14
Solved Threads: 9
Light Poster
Daiva is offline Offline
37 posts
since May 2009
Sep 1st, 2010
0
Re: $_FILES empty
Click to Expand / Collapse  Quote originally posted by Daiva ...
Works good for me...
I have noticed $appId variable. Maybe you are using it for a Facebook application?
Not facebook, designing web apps for my University. appId is something for the main web server that houses all the web apps. Think I'll have to mess with some php.ini settings, see if that fixes it...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
awestove is offline Offline
8 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Using Google SMTP to send mail in PHP
Next Thread in PHP Forum Timeline: Cast Object to Array in object construct





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC