Fopen (uploadedimages /): Failed to open stream: No such file or directory in
I am following the tutorial on uploading image from android to server and I am using php 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 a resource, boolean in ... fclose () expects parameter 1 to be a resource, boolean in ...
I am very new to php, so please help me (I found some answers from the internet, but it didn't work for me)
source to share
You need to provide the full path to the file in fopen()
$file = fopen($_SERVER['DOCUMENT_ROOT'].'/uploadedimages/'.$filename, 'wb');
Also make sure you have permissions to create the file on your server.
And since no file is created in the first place you get errors when you try to use fwrite()
andfclose()
source to share