Jump to content


Having a problem using POST

  • Please log in to reply
1 reply to this topic

#1 dynomonkey

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 October 2006 - 09:12 PM

Hi everyone,

Ive been working on a simple system that allows files to be uploaded to my server and I'm having problems receiving the $_POST and $_FILES variables from my form. It appears the POST method isnt working for sum reason. here is my code:

<form action="procnewsletter.php" method="post" enctype="multipart/form-data">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<td>Title: </td>
<td><input type="text" name="title"></td>
      <td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
      <input name="userfile" type="file" class="box" id="userfile">
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>

And the proccessing page (procnewsletter.php) does the following:

$title = $_POST['title'];
echo $title;

$uploadDir = 'Files/Newsletters/';

if (!is_uploaded_file($_FILES['userfile']['tmp_name'])) {
  echo "You did not upload a file!";

    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $filePath = $uploadDir . $fileName;

if(move_uploaded_file($tmpName, $filePath)) {
    echo "The file has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";

I always receive the "You did not upload a file!" error, and nothing is stored in the variables i created. This is because nothing seems to be passed in the header when using POST method. so I cant retreive any of the information entered in the form.  IF i remove method="post" from the form then i can get the title using $_REQUEST['title] but i still dont get anything in the $_FILES array.

Any help would be much much much appreciated.

Thank you very much.

#2 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 October 2006 - 09:53 PM

I copied your script to my server where it ran fine. Put these lines at the start of the processing script:
echo '<pre> --- $_POST --- ' . print_r($_POST,true) . '</pre>';
echo '<pre> --- $_FILES --- ' . print_r($_FILES,true) . '</pre>';

This will dump what the script is recieving from the form and may give you a hint as to what is wrong.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users