I try to send a photo and GPS location to server via PHP
here is the PHP part:Copy from here Saving the Uploaded File
The examples above create a temporary copy of the uploaded files in the PHP temp folder on the server.
The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
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("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
The script above checks if the file already exists, if it does not, it copies the file to the specified folder.
Note: This example saves the file to a new folder called "upload"
now back to iOS part ,I only can send GPS location to server ,it's easy because just a string.
and you can download sample code here
But an image is not,I do some search and found this discussion
I directly put the code in my send GPS&image button
the best thing is it can feedback I send the file success or failed
this is the most message I got after I send photo to server
1.Invalid file
2.Return Code:
Upload:
Type:
Size: 0 Kb
Temp file:
Stored in: upload/
I follow some guide to save image to NSData
NSData *photoData= UIImageJPEGRepresentation(self.theimageView.image, 1.0);
and I also check there is data inside or not
so simply add this code into Button action
if (photoData == nil) {
NSLog(@"The photo is nothing !!!");
}
else {
NSLog(@"Photo inside !!!!");
It works fine.......
But How To Upload An Image To Server ???
maybe I need to give a file name then upload it ???
but how to...
I never use camera function and upload data before
Hope someone can figure out this problem
Many Great Thanks !!!