I have written a piece of PHP code to upload image files to a specified server directory and associate them with events. The code works fine on server A that I built it on, but when moving it to server B where it will live, it has ceased to work.
The issue seems to relate to the "enctype" variable in the form definition. When enctype is set to "multipart/form-data" as you require, NO variables get passed to the PHP page called by the "action" variable in the same form definition. However, if I remove the "method=post" tag at the end of this line, so that the method is now get, then some variables ARE passed. The problem being that now the image uploading stuff isn't passing the correct information across because it is using the GET method.
Can anyone suggest what is causing this? I've included the code below for reference...
<form name="page" action="events.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000">
...
print ("<img src=\"../eventimages/$data[$n]\"><br>Enter new image: <input name=\"image\" type=\"file\">");
...
<input type="submit" value="Update Now" name="submit">
</form>
and then on SUBMITing the following script is called:
if (($image == "") || ($image == "\n") && ($oldimage != ""))
{
$image_filename = "";
}
else
{
$youwhat = $HTTP_POST_FILES['image']['type'];
if ($youwhat == "image/gif" || $youwhat == "image/jpeg" || $youwhat == "image/jpg" || $youwhat == "image/png" || $youwhat == "image/pjpeg" || $youwhat == "image/x-png")
{
$time_tmp = time();
$image_filename = $time_tmp . "_" . $HTTP_POST_FILES['image']['name'];
$image_savepath = "../eventimages/$image_filename";
move_uploaded_file($image, $image_savepath);
}
else
{
$image_filename = "";
print ("Sorry, but this file type is not recognised as an image, please check and try <a href=\"javascript: history.go(-1)\">again</a>.");
}
}
If anyone can help with this I would be VERY grateful as it's sending me bonkers!