Save image url to Mysql Database

后端 未结 2 869
执念已碎
执念已碎 2021-01-24 14:58

I have a database named \'mysqlproject\' that contains two tables. One of the tables that i am interesting in is named markers and declared in database like this :



        
2条回答
  •  佛祖请我去吃肉
    2021-01-24 15:26

    Found it!

    define('UPLOAD_DIR', 'EventImages/');
    $img = $_POST['imgBase64'];
    $img = str_replace('data:image/png;base64,', '', $img);
    $img = str_replace(' ', '+', $img);
    
    
    $data = base64_decode($img);
    $file = UPLOAD_DIR . uniqid() . '.png';
    $success = file_put_contents($file, $data);
    print $success ? $file : 'Unable to save the file.';
    
    
    $result=mysql_query("SELECT id FROM markers ORDER BY id DESC LIMIT 1");
    while ($row = mysql_fetch_array($result)){
    $LastInsertID=$row['id'];
    }
    $results = mysql_query("UPDATE markers SET PhotosEvent='".$file."' WHERE id = '".$LastInsertID."'");    
    

    now it works ok.. I am fetcing the last known id that is in table Markers and i save the image's url that is stored in variable $file in the database!! I also save the image to folder EventImages as i did before!!

提交回复
热议问题