Jump to content

validate and before moving file to directory and get it's name to database(base64 image upload)


Recommended Posts

I have a form on which the filepond plugin send the file manually
 and it generate the base64 formated data of that file, unfortunately
Icant get it's previous name so i randomize the name, and put the file directry in the final folder, is there any problem on security?, can i validate if its an image with all property such as size,dimension e.t.c Before adding it the directory? and how to get the it's
new name to database.


Look here

if(empty($_POST['image'])) {
    echo 'add file!';
$myimage = $_POST['image'];
$myimage = str_replace('data:image/png;base64,', '', $myimage);
$myimage = str_replace(' ', '+', $myimage);
$decode = base64_decode($myimage);
$myfile = $_SERVER['DOCUMENT_ROOT'].'/mages/' . uniqid() . '.png';
//now put the file
file_put_contents($myfile, $decode);


Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.