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.
Related
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
<?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 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 am facing the task of having to upload a snapshot to the server. But I don't want the user to download the image to their computer.
I have explored a few solutions of generating an image serverside with PHP, but they all seem to use a method where the server sends the image to the user.
See for instance: http://mattkenefick.com/blog/2008/11/06/saving-jpegs-with-flash/
I'm wondering if it's possible to save $GLOBALS["HTTP_RAW_POST_DATA"], which in that example contains the ByteArray sent by Flash, to the server as an image file....
Use php code that is along these lines to save the contents of $GLOBALS["HTTP_RAW_POST_DATA"]
// untested code
$imageBytes = $GLOBALS["HTTP_RAW_POST_DATA"]
// in real code you better create a new file for every upload :-)
$file = fopen("uploads/test.jpg", "w");
if(!fwrite($file, $imageBytes)){
return "Error writing to file: $file";
}
fclose($file);