user3840898
user3840898

Reputation: 197

2174 error on upload image base64 in php

hi use the following code as below

if($data['photo']!='')
{
    define("UPLOAD_DIR", "admin/alumni_image/");
    $photo = $data['photo'];// THIS IS YOUR BASE64 ENCODED STRING
    $photo = str_replace('data:image/png;base64,', '', $photo);
    $photo = str_replace(' ', '+', $photo);
    $data = base64_decode($photo);
    $time =microtime(true);
    $micro_time=sprintf("%06d",($time - floor($time)) * 1000000);
    $date=new DateTime( date('Y-m-d H:i:s.'.$micro_time,$time) );
    $currentDatetime=$date->format("Y-m-d H:i:s.u"); 
    $file = UPLOAD_DIR . md5($currentDatetime) . '.png';
    $array=explode("/",$file);
    $photoName=$array[2];
    $success = file_put_contents($file, $data);

    echo $success;
    $query_photo = "update alumni set photo = '".$photoName."' where alumni_id = '".$insert_id."'";
    $query_run=  mysql_query($query_photo);
}

but I got error 2174. I increase the size of php configuration file like

ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');  

Upvotes: 0

Views: 58

Answers (1)

Niels Keurentjes
Niels Keurentjes

Reputation: 41958

The return value of file_put_contents is not an error code:

This function returns the number of bytes that were written to the file, or FALSE on failure.

Thus there appears to be nothing wrong with your code.

Upvotes: 2

Related Questions