Jump to content


This topic is now archived and is closed to further replies.


Having a problem using POST

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">
<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.

Share this post

Link to post
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:
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.


Share this post

Link to post
Share on other sites


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.