I'm writing image files from a base64 encoded string with a php webservice in this very same folder using file_put_contents()
.
Here is the writing part [PHP]:
$data = base64_decode( $datastring );
$res = file_put_contents( $path, $data );
$resultf = array();
$resultf["request"] = "setpic";
$resultf["result"] = strval($res);
$this->sendResponse(200, json_encode($resultf));
And the reading part follows [PHP]:
$datastring = file_get_contents( $path );
$data = base64_encode( $datastring );
$resultf["request"] = "getpic";
$result0 = array();
$result0["path"] = $path;
$result0["data"] = $data;
$resultf["result"] = $result0;
$this->sendResponse(200, json_encode($resultf));
The two $path
are correct.
Nevertheless although the files are "correctly" created (I can see them with ssh
with a size of approx. 9kB),
if I scp
the image files they appear to have a width and height of 0, ie a corrupted image file I presume.
If I try to load them using XCode in my iOS app, I get the following error:
ImageIO: <ERROR> JPEG Corrupt JPEG data: 75 extraneous bytes before marker 0xdb
Please note that containing folders have 777 permissions, same user/group than the php webservice accessing them form a parent folder. This method worked until I unfortunately changed the owner of the root folder.
Thanks a lot for your help.