Jump to content

$_POST not working


Meridius

Recommended Posts

Hello,

 

I am trying to pass variables to a page, should be an easy job you say? Same thoughts here but i can't really find the problem.

For starters I have a simple form with a textfield and a upload field. (i'm a dutchy so labels/errors will be foreign to most)

<form action="upload_exec.php" method="post" enctype="multipart/form-data">
<table border="0">
<tr>
	<td>Mapnaam:</td>
	<td><input type="text" name="folder" size="35" /></td>
</tr>
<tr>
        <td>Bestanden:</td>
	<td><input type="file" name="file[]" id="file" multiple=""/></td>
</tr>
<tr>
	<td colspan="2" align="right"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>

 

Basically i can't see anything wrong with it, on the form action page i constantly get the error message saying the variable isn't filled.

<?php
include('ResizeImage.php');

if (!isset($_POST['folder'])) 
{
	echo "Er is geen map aangegeven";
}
else 
{
	$dirname = $_POST["folder"];
	$filename = ('./' . $dirname . '/');

	if (!file_exists($filename)) 
	{
		mkdir("{$dirname}");
	}

	for($i = 0; $i < count($_FILES['file']['name']); $i++)
	{
		$allowedExts = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png");
		$extension = end(explode(".", $_FILES["file"]["name"][$i]));
		if ((($_FILES["file"]["type"][$i] == "image/gif")
		|| ($_FILES["file"]["type"][$i] == "image/GIF")
		|| ($_FILES["file"]["type"][$i] == "image/jpeg")
		|| ($_FILES["file"]["type"][$i] == "image/JPEG")
		|| ($_FILES["file"]["type"][$i] == "image/pjpeg")
		|| ($_FILES["file"]["type"][$i] == "image/PJPEG"))
		&& ($_FILES["file"]["size"][$i] < 200000000)
		&& in_array($extension, $allowedExts))
		{
			if ($_FILES["file"]["error"][$i] > 0)
			{
				echo "Foutode: " . $_FILES["file"]["error"][$i] . "<br />";
			}
			else
			{					
				if (file_exists("" . $dirname . "/" . $_FILES["file"]["name"][$i]))
				{
					echo $_FILES["file"]["name"][$i] . " already exists. <br />";
				}
				else
				{
					move_uploaded_file($_FILES["file"]["tmp_name"][$i],
					"" . $dirname . "/" . $_FILES["file"]["name"][$i]);
					echo "Opgeslagen in: " . "" . $dirname . "/" . $_FILES["file"]["name"][$i] . " <br />";
					  
					$image = new ResizeImage();
					$image->load("" . $dirname . "/" . $_FILES["file"]["name"][$i]);
					$image->resizeToHeight(1080);
					$image->save("" . $dirname . "/" . $_FILES["file"]["name"][$i]);
					$image->resizeToHeight(38);
					$image->save("" . $dirname . "/thumb_" . $_FILES["file"]["name"][$i]);
				}
			}
		}
		else
		{
			echo "Geen geldig bestand <br />";
		}
	}
}
?>

 

Any insights would be really helpfull or maby a work-around if this doesn't work.

Is it an idea to use $_GET or sessions if nothing seems wrong?

I have tested in Chrome, FireFox 14, IE 9 and all give the same result.

 

Kind regards/Thanks in advance,

Erik

Link to comment
Share on other sites

See what your $_POST and $_FILES arrays actually contain when the form is submitted and use that information to start debugging the problem.

 

echo '$_POST array:<pre>';
print_r($_POST);
echo '</pre><br>$_FILES array:<pre>';
print_r($_FILES);
echo '</pre>';

Link to comment
Share on other sites

Thanks all for the very quick responses.

I put both codes in the form action file and well, here are the results:

ChristianF code:

array
  empty
array
  empty

 

Pikachu2000 code:

$_POST array:
Array
(
)

$_FILES array:
Array
(
)

 

I tried it again after closing all the browsers and then restarting WAMP fully before trying again.

It seems to work fine for a single file but when selecting multiple it seems to fail.

Link to comment
Share on other sites

Sorry scootstah, i missed your post. You seem to have very very good point there!

 

I have tested some things and indeed when choosing smaller images it results in success so the uploads have indeed exceeded the maximum size it seems.

I will have to sort that out later today since i have to go now but thanks so much for pointing me to it.

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.