I have my Android Client - which send the binary base64 to the PHP server (Image - JPG/JPEG).
And here is my PHP server code to save the picture and decode the binary.
Now I want to check more about the file, so the FileSize, FileType but I found no possible function. I tried mime type but I couldn't make it.
Does anyone have an example for me?
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_image.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo 'true';
Thanks
you can use
$desc_array = stat('uploaded_image.jpg');
to get more information like
$desc_array["size"];
see http://php.net/manual/de/function.stat.php
Related
<?php
// Get image string posted from Android App
$base=$_REQUEST['image'];
// Get file name posted from Android App
$filename = $_REQUEST['filename'];
// Decode Image
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploads/'.$filename, 'wb');
// Create File
fwrite($file, $binary);
fclose($file);
echo 'Image upload complete, Please check your php file directory';
?>
This my php code for get image string and filename posted from Android App.I need to create temprory file name for the image.Can anyone help?.
If you're wanting to generate a unique temporary filename can you use a GUID perhaps?
http://php.net/manual/en/function.com-create-guid.php
To create a temporary filename take a look at tempnam(), which "creates a file with a unique filename, with access permission set to 0600, in the specified directory."
https://secure.php.net/manual/en/function.tempnam.php
i am a newbie android programmer, i not good at website design. However, i have a project send image from android to website, image is sent from android to website ok fine when i use this script
<?php
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_image.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo 'Image upload complete!!, Please check your php file directory……';
?>
and my picture located here.
but now i would like to show image in web page(in my website nns12151069.esy.es), what should i write more in script .php
Please lookup the file upload with php http://www.w3schools.com/php/php_file_upload.asp
another hand you can call directly your image from uploaded path
I have uploaded a file from my smartphone to server using PHP. This PHP side is only for test (because I'm testing that my android app works properly or not...), and there is no problem with client and/or server side.
But my main task is writing this server in WCF... I don't know how can I do it.
My PHP codes looks like:
<?php
// Get image string posted from Android App
$base=$_REQUEST['image'];
// Get file name posted from Android App
$filename = $_REQUEST['filename'];
// Decode Image
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
// Images will be saved under 'www/imgupload/uplodedimages' folder
$file = fopen('uploadedimages/'.$filename, 'wb');
// Create File
fwrite($file, $binary);
fclose($file);
echo 'Image upload complete, Please check your php file directory';
?>
If you know please help me... Actually I'm going to be crazy :(
Any comment and/or answer appreciate.
Thanks a lot.
I just use the following php code but encoded image requires more memory so that i want to use stream method. Please anyone suggest me. Advance thank you.
<?php
$base=$_REQUEST['image'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('uploaded_image.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo 'Image upload complete!!, Please check your php file directory……';
?>
Just set a higher max_upload_size in your webserver's config.
I have a jpg blob thats been stored in an external DB and I'm looking to display that as an image via php. The issue is whenever I set the Content-Type to image/jpeg and echo out the blob I get the broken image icon when browsing to it.
I have tried making the file from scratch via sublime and that works when I save it as a hexadecimal file so I know the data is valid.
I have tried making the script create a file but it sets the charset=us-ascii so it won't get seen as a image file.
Does anyone have any experience with raw image binary files? anyone know how I can display the image or even save it out to a file?
Thanks in advance.
P.S. I would provide the binary but its just too big to put on here.
EDIT: (added some code)
<?php
header('Content-Type: image/jpeg;');
$data = 'some long string of hex';
// tried echoing it directly..
echo $data;
// and writing to a file...
file_put_contents('test.jpg', $data);
?>
After continuing research I found this post PHP: create file from an HEX string
With the following code I fixed the issue.
<?php
header('Content-Type: image/jpeg;');
$data = 'The hex data';
$data = pack('H*',$data);
$im = imagecreatefromstring($data);
imagejpeg($im);
?>
Try $im = imagecreatefromstring($data); The output it by imagejpeg($im);