Send a url to a database

0

Image of the table images: link

Hi, I was doing a drawing game made with canvas and I have a "Upload" button with which I would like to upload the url of the image to the bd.

I have a function with which I can create a canvas url:

function pujar() {
var canvas = document.getElementById("canvas");

canvas.toBlob(function(blob) {
    var novaImatge = document.createElement("img"),
    url = URL.createObjectURL(blob);
    alert(url);

    novaImatge.onload = function() {
        URL.revokeObjectURL(url);
    };

    novaImatge.src = url;

    $('#pujar').remove();
});

My question comes here: Is there a way to call a php file inside the function to insert the url in the table? Right now my php file looks like this:

insert.php

include 'templates/database.inc.php';

//Per a afegir
include_once 'templates/magicquotes.inc.php';

try {
    $sql = 'INSERT INTO imatges SET url = :"contingut"';
    $s   = $pdo->prepare($sql);
    $s->execute();
}
catch (PDOException $e) {
    $error = 'No se ha pogut insertar la imatge: ' . $e->getMessage();
    include 'templates/error.html.php';
    exit();
}

header('Location: .');

exit();
    
asked by DeNick_ZaM 16.05.2018 в 16:08
source

1 answer

0

The first thing you should do is to get the root where the images are being loaded, something like this:   ./ scripts / images / That would be the route where the images are stored, then concatenate it with the name of the image which you can take out in the function that you have to attach it.

and it would only be to assign that complete path to a variable and save it in the database as a string.

In conclusion only verify that the images are uploading to the directory, and then you get that path with the name of the image that is to be saved in the url field of your database

I hope I helped you with the concern.

    
answered by 18.05.2018 в 03:21