V
V
Vladimir Tyutimov2015-07-16 17:26:01
PHP
Vladimir Tyutimov, 2015-07-16 17:26:01

How to save image to server from base64?

Hello. I'm trying to save a base64 image to disk. Not saved. What is the reason how to solve?
Here is the code:

$imagee = base64_decode($Product->Изображение->Данные);
        $FPName = $products[$i]['ID'].'.'.$Product->Изображение->Расширение;
        $FPPath = '/img/'.$FPName;
        file_put_contents($FPPath, $imagee, LOCK_EX);

And yes, all this is in the Bitrix component, if it affects something.
If the path is not specified in the $FPPath variable, then everything is saved, but I need to save it to this folder.
Folder permissions set to 777

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Burov, 2015-07-16
@BidiBom

You have an absolute path.
Either write full from the root of the server, or relative
$FPPath = './img/'.$FPName;

A
Alexander Aksentiev, 2015-07-16
@Sanasol

stackoverflow.com/questions/11511511/how-to-save-a...

D
Dark_Scorpion, 2016-04-08
@Dark_Scorpion

file_put_contents($FPPath, $imagee, LOCK_EX);

And what did CFile::SaveFile not please?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question