Display image in web use file .php - 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

Related

How to create temporary filename for image posted from Android App

<?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

Upload file to server using WCF

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.

How to upload large size image from android application to server in php using stream method or multipart method?

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.

Renaming file while downloading from other website

I am trying to rename file and download it for user!
Example... In my website I offer to download Google Logo from my website link!
http://www.mywebsite.com/files/logo-mysite.jpg
then the file is saved as logo-mysite.jpg in the users computer but the file in real is downloaded from https://www.google.co.in/images/srpr/logo4w.png
We can do it by saving the image from https://www.google.co.in/images/srpr/logo4w.png temporary to our website and then auto-delete it on download or auto-delete within 1 hour!
You can suggest a filename for a download by adding a content-disposition header:
header('Content-disposition', 'attachment;filename=logo-mysite.jpg');
die(file_get_contents('https://www.google.co.in/images/srpr/logo4w.png'));
Obviously this would give problems since you are downloading a png file with a jpg extension, but I'm just following your question... To convert the image you'd need to add some lines of GD2 code.
Use the header() function to set the name that the user will download:
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename=logo-mysite.png');
// Open the new file, and dump it out to the user
$handle = fopen( "https://www.google.co.in/images/srpr/logo4w.png" );
fpassthru( $handle );
fclose( $handle );
If you really want to convert it from jpg to png, you'll need to run it through ImageMagick or the likes.

download image from wamp server and save in my folder loacated in same using php

hello friends i want to save image from my wamp server to my specific wamp project folder i have used below code ,this code show me the dialog to save image but i want to call image from wamp server and save it in my folder
<?php
header('Content-type: image/png');
$imageUrl = "http://ip/demo/images/itemimage/Platters.png";
$filename = realpath(dirname("http://ip/demo/images/itemimage/Platters.png"))."/image1.png";
$handle = file_get_contents($imageUrl);
file_put_contents($filename, $handle);
?>
this code do not download image automatically to my folde can any one help me ?
i got ths error with above code
The problem is you do two things on your script. You set the image to deliver the image over the php script.
<?php
header('Content-type: image/png');
echo file_get_contents("http://ip/demo/images/itemimage/Platters.png");
?>
Then you should fetch the image and send the image with echo to the user.
When you want to save the image then you need only fetch the image with file_get_contents and put them to your harddrive what you do at the moment.
I think in your example the echo missing this is why you get the error. You set the content type of the site but you don't deliver any png data.
<?php
header('Content-type: image/png');
$handle = file_get_contents("http://ip/demo/images/itemimage/Platters.png");
file_put_contents(dirname(__FILE__).md5(time()), $handle);
echo $handle;
?>
Edit: Try something like this. Then he should save the image in the same path.
One way:
exec("wget http://ip/demo/images/itemimage/Platters.png /tmp/demo/images/itemimage/Platters.png");

Categories