Jump to content

wont read 'POST' data...


Twentyoneth

Recommended Posts

this is my script:

[code]<?php
        $writedir = "files/";
        $upl = $HTTP_POST_FILES['upl'];
        $rename = ($writedir . $_POST['rename']);
        $uploadfile = ($writedir . basename($HTTP_POST_FILES['upl']['name']));

        echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile);

      if($_POST['Upload']) {
        if (move_uploaded_file($upl, $uploadfile)) {
            rename($uploadfile, $rename);
            echo ("Your file was successfully uploaded.<br>");
            } else {
            echo "Could not upload file.<br>";
            }
        } else {
            echo "<form action='upload.php' enctype='multipart/form-data' method='POST'>
<input type='hidden' name='MAX_FILE_SIZE' value='9000000000000' />
<table border='0'>
<tr>
<td>
    Browse for a file, give it a name. Then 'Upload' it.
</td>
</tr>
<tr>
<td>
    <input type='file' name='upl' />
</td>
</tr>
<tr>
<td>
    <input type='text' name='rename' />
    <input type='submit' value='Upload' name='Upload' />
</td>
</tr>
</table?
</form>";

        }

?>[/code]

For some reason, it will not read any of the post data. I tried to have it check what each little variable was holding but they are all empty. Can anyone help tell me what is wrong and get this script working?
Link to comment
Share on other sites

Uhm for one....wildteen hes not using $HTTP_POST_VARS

Second...Try checking your form page make sure your name is exactly "Upload" and if it is try making $_POST['Upload'] a variable such as

[code]
<?php
$Upload = $_POST['Upload'];

// To check if the variable is populated
echo $Upload;
?>
[/code]
Link to comment
Share on other sites

Use $_FILES  instead of $HTTP_POST_FILES.

At the start of the script put:
[code]<?php
echo '$_POST:<pre>' . print_r($_POST,true) . '</pre>';
echo '$_FILES:<pre>' . print_r($_FILES,true) . '</pre>';
?>[/code]

This will tell you what's being returned to your script from the form.

Ken
Link to comment
Share on other sites

[code]<html>
<head>
</head>
<body>

<?php
        $writedir = "files/";
        $upl = $_FILES['upl'];
        $uploadfile = ($writedir . $_POST['rename']);
      if($_POST['Upload']) {
        if (move_uploaded_file($upl, $uploadfile)) {
            echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile . "<br>");
            echo ("Your file was successfully uploaded.<br>");
            } else {
            echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile . "<br>");
            echo "Could not upload file.<br>";
            }
      } else {
echo "<form action='" . $_SERVER['PHP_SELF'] . "' enctype='multipart/form-data' method='POST'>
<input type='hidden' name='MAX_FILE_SIZE' value='9000' />
<table border='0'>
<tr>
<td>
    Browse for a file, give it a name (with extention). Then 'Upload' it.
</td>
</tr>
<tr>
<td>
    <input type='file' name='upl' />
</td>
</tr>
<tr>
<td>
    <input type='text' name='rename' />
    <input type='submit' value='submit' name='Upload' />
</td>
</tr>
</table>
</form>";

}

?>

</body>
</html>[/code]
Link to comment
Share on other sites

Guest rancid-tea
I was able to get it to function on my test server with the following modification:

[code]...
if (move_uploaded_file($_FILES['upl']['tmp_name'], $uploadfile)) {
...[/code]

I also had to ensure that the files directory existed.

To get your echo statements to print relevant information, I added :

[code] $rename = $_POST['rename'];[/code]

You don't need the above change if you have globals on, but you should use it to be safe.

I also changed your long echo statement to this:

[code]echo ("writedir = " . $writedir . "<br>\n upl = <pre>");
print_r($_FILES['upl']);
echo ("</pre> " . "rename = " . $rename . "<br>\n" . "uploadfile = " . $uploadfile . "<br>");[/code]

I hope that helps!
Link to comment
Share on other sites

I am using firefox, I have tried return/enter key, and using the mouse. I added the bit of code to my form and still nothing....I have also split the code up into two different files, one is the form in html, and the other (upload2.php) is only the php....and it still will not work, is it just my system?
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.