I'm following a tutorial to upload a picture from android to server and i'm using php on server side and this is the code:
<?php
error_get_last();
chmod("./uploadedimages/", 777);
// 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';
?>
When i try to run, it shows me the following errors:
fopen(uploadedimages/): failed to open stream: No such file or directory in...
fwrite() expects parameter 1 to be resource, boolean given in... fclose() expects parameter 1 to be resource, boolean given in...
I'm very new to php so please help me ( I've found some answers from the internet but it didn't work for me)
You need to give full path of the file in fopen()
$file = fopen($_SERVER['DOCUMENT_ROOT'].'/uploadedimages/'.$filename, 'wb');
Also make sure you have the right permissions to create a file in your server.
And since the file is not getting created in the first place, you are getting errors when you are trying to use fwrite() and fclose()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With