PHP - Como guardo la imagen a la base de dato teniendo el siguiente código?

 
Vista:

Como guardo la imagen a la base de dato teniendo el siguiente código?

Publicado por Britny (1 intervención) el 06/08/2019 19:22:19
Hola, Tengo este código y no sé como hacer para guardar la imagen seleccionada en la base de datos.....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var last_gritter
$('#avatar').editable({
 
    type: 'image',
                            method: 'POST',
    name: 'avatar',
    value: null,
    //onblur: 'ignore',  //don't reset or hide editable onblur?!
    image: {
        //specify ace file input plugin's options here
        btn_choose: 'Change logotype',
        droppable: true,
        maxSize: 110000,//~100Kb
 
        //and a few extra ones here
        name: 'avatar',//put the field name here as well, will be used inside the custom plugin
        on_error : function(error_type) {//on_error function will be called when the selected file has a problem
            if(last_gritter) $.gritter.remove(last_gritter);
            if(error_type == 1) {//file format error
                last_gritter = $.gritter.add({
                    title: 'File is not an image!',
                    text: 'Please choose a jpg|gif|png image!',
                    class_name: 'gritter-error gritter-center'
                });
            } else if(error_type == 2) {//file size rror
                last_gritter = $.gritter.add({
                    title: 'File too big!',
                    text: 'Image size should not exceed 100Kb!',
                    class_name: 'gritter-error gritter-center'
                });
            }
            else {//other error
            }
        },
        on_success : function() {
            $.gritter.removeAll();
        }
    },
    url: function(params) {
        // ***UPDATE AVATAR HERE*** //
        //for a working upload example you can replace the contents of this function with 
        //examples/profile-avatar-update.js
 
        var deferred = new $.Deferred
 
        var value = $('#avatar').next().find('input[type=hidden]:eq(0)').val();
        if(!value || value.length == 0) {
            deferred.resolve();
            return deferred.promise();
        }
 
 
        //dummy upload
        setTimeout(function(){
            if("FileReader" in window) {
                //for browsers that have a thumbnail of selected image
                var thumb = $('#avatar').next().find('img').data('thumb');
                if(thumb) $('#avatar').get(0).src = thumb;
            }
 
            deferred.resolve({'status':'OK'});
 
            if(last_gritter) $.gritter.remove(last_gritter);
            last_gritter = $.gritter.add({
                title: 'Logotype Updated!',
                text: 'Great',
                class_name: 'gritter-info gritter-center'
            });
 
 
 
         } , parseInt(Math.random() * 800 + 800))
 
        return deferred.promise();
 
        // ***END OF UPDATE AVATAR HERE*** //
    },
 
    success: function(response, newValue) {
    }
})
}catch(e) {}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Como guardo la imagen a la base de dato teniendo el siguiente código?

Publicado por joel (1269 intervenciones) el 06/08/2019 22:21:58
Este código es de javascript... de alguna manera, tienes que enviar la imagen al servidor para poder gestionarla con PHP y guardarla en la base de datos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Mauro
Val: 2.761
Oro
Ha aumentado 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

Como guardo la imagen a la base de dato teniendo el siguiente código?

Publicado por Mauro (1037 intervenciones) el 07/08/2019 16:47:27
Yo te recomendaría que no guardes la imagen en la base de datos. Una alternativa puedes verla aquí.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar