Jump to content

Having a problem using POST


dynomonkey

Recommended Posts

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">
    <tr>
<td>Title: </td>
<td><input type="text" name="title"></td>
</tr>
     <tr> 
      <td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
      <input name="userfile" type="file" class="box" id="userfile">
         </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
    </tr>
  </table>
</form>

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.
Link to comment
Share on other sites

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

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

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.