Hi,
I have more or less finished an app and it works perfectly on my shared server… I have a VPS which I now intent to use because it should be more reliable and faster. I have moved all my files over to the new server and everything seems to work perfectly except for the image uploads… It appears that no content-type is getting passed across. I get the following error (from the php error log file) at the moment - “PHP Notice: Undefined index: myfile”, this comes from the line "echo “Named: " .$_FILES[“myfile”][“name”]. “<br>”;” I am using the multipart form example found here. As I said this worked perfectly on the old server. Does anyone have any ideas why it does not work on the new server, I have asked my server and they are looking into it, but at the moment they think the error is on my side not theirs.
I have also tried using network.upload() and cannot get this to work on either my old or new server. Here is the code I am using… It also appears that no content type is being passed across. (the PHP file jumps too - echo “Invalid file - No content type”; - which indicates that there is no content type.
Thanks Craig
[lua]
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
elseif ( event.phase == “ended” ) then
print ( “Upload complete!” )
print ( "RESPONSE: " … event.response)
end
end
network.upload(
“http://inspectionapp.myserver.co.nz/upload_files.php”,
“POST”,
networkListener,
“Image.jpg”,
system.DocumentsDirectory,
“image/jpg”
)
[/lua]
And my php file
[lua]
<?php
$allowedExts = array(“gif”, “jpeg”, “jpg”, “png”);
$extension = end(explode(".", $_FILES[“file”][“name”]));
echo "Named: " .$_FILES[“filename”][“name”]. “<br>”;
echo "Type: " .$_FILES[“filename”][“type”] . “<br>”;
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “image/jpg”)
|| ($_FILES[“file”][“type”] == “image/pjpeg”)
|| ($_FILES[“file”][“type”] == “image/x-png”)
|| ($_FILES[“file”][“type”] == “image/png”)))
{
if ($_FILES[“file”][“error”] > 0)
{
echo "Return Code: " . $_FILES[“file”][“error”] . “<br>”;
}
else
{
echo "Upload: " . $_FILES[“file”][“name”] . “<br>”;
echo "Type: " . $_FILES[“file”][“type”] . “<br>”;
echo “Size: " . ($_FILES[“file”][“size”] / 1024) . " kB<br>”;
echo "Temp file: " . $_FILES[“file”][“tmp_name”] . “<br>”;
if (file_exists("/images/" . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . " already exists. ";
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“/images/” . $_FILES[“file”][“name”]);
echo "Stored in: " . “/images/” . $_FILES[“file”][“name”];
}
}
}
else
{
echo “Invalid file - No content type”;
}
?>
[/lua]