I am trying to send a photo and GPS location to a server via PHP
here is the part of PHP: copy here Saving the downloaded file
The above examples create a temporary copy of the downloaded files in the PHP temp folder on the server.
Temporary copied files disappear when the script ends. To save the downloaded file, we need to copy it to another 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 above script checks if the file exists, if it does not exist, it copies the file to the specified folder.
Note. In this example, the file is saved in a new folder named "upload"
Now back to the iOS part, I can send the GPS location to the server, it's just because it's just a string.
and you can download the sample code here
But there is no image, I do a search and found this discussion
I directly put the code in my GPS & Image Submit button
Best of all, it could be feedback. I'm sending a file or failing
this is the biggest message I received after sending the photo to the server
1. Invalid file
2.Back Code:
Download:
A type:
Size: 0 Kb
Temp file:
Saved in: upload /
The following guide to saving an image to NSData p>
NSData *photoData= UIImageJPEGRepresentation(self.theimageView.image, 1.0);
and I also check if there is data inside or not
so just add this code to the button action
if (photoData == nil) { NSLog(@"The photo is nothing !!!"); } else { NSLog(@"Photo inside !!!!");
It works great .......
But how to upload the image to the server ???
Maybe I need to specify a file name and then upload it.
but how...
I never use the camera function or upload data before
Hope someone can understand this problem
Thank you very much!