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)

+3


source to share


2 answers


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()

+3


source


The error failed to open stream

occurs when PHP cannot find the path you specified. And also consider that you did not specify the file extension, so use something like fopen('uploadedimages/'.$filename.'.png', 'w+')

. An extension might be your preferred choice.



0


source







All Articles