Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Implementar QR Code images usando Google Chart API

Estas en el tema de Implementar QR Code images usando Google Chart API en el foro de PHP en Foros del Web. Saludos chicos, en esta oportunidad estoy implementando una sencilla api para generar un codigo QR esa parte la tengo ya funcionando, con este codigo: Código ...
  #1 (permalink)  
Antiguo 29/01/2017, 20:40
(Desactivado)
 
Fecha de Ingreso: septiembre-2008
Ubicación: Maracay edo Aragua Venezuela
Mensajes: 48
Antigüedad: 15 años, 7 meses
Puntos: 3
Pregunta Implementar QR Code images usando Google Chart API

Saludos chicos, en esta oportunidad estoy implementando una sencilla api para generar un codigo QR esa parte la tengo ya funcionando, con este codigo:

Código PHP:
//RUTAS
 
$basedesitio "http://sitiodeejemplo.com";
 
$inicio '/index.php';
 
$pngqr '/codigosqr';
 
$operador'?buscar=';
// $rutalibqr= '../../../../qr/qrlib.php';
 
$rutalibqr'./qr/qrcode.php';
 
$rutapngqr'/codigosqr/';
//INCLUYENDO LIBRERIA QR
include  $rutalibqr;
$qr = new qrcode();
//link
$qr->link($webdata);
echo 
"<p>Link</p>";
echo 
"<p><img src='".$qr->get_link()."' border='0'/></p>"
pero no logro comprender como puedo guardar la imagen generada en el servidor.
Código PHP:
//SALVAR PNG EN SERVIDOR
$file $qr->get_image();
$path=  $rutapngqr;
$qr->save_image($file$path); 
Dejo por aca el Scrip de la API a ver si alguno me colabora en mi duda,

Código PHP:
<?php  
/*************************************************************  
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com  
 * Fee free to distribute and modify code, but keep reference to its creator  
 *  
 * This class generate QR [Quick Response] codes with proper metadata for mobile  phones  
 * using google chart api http://chart.apis.google.com  
 * Here are sources with free QR code reading software for mobile phones:  
 * http://reader.kaywa.com/  
 * http://www.quickmark.com.tw/En/basic/download.asp  
 * http://code.google.com/p/zxing/  
 *  
 * For more information, examples and online documentation visit:   
 * http://webcodingeasy.com/PHP-classes/QR-code-generator-class  
 **************************************************************/  
class qrcode  
{  
    private 
$data;  
      
    
//creating code with link mtadata  
    
public function link($url){  
        if (
preg_match('/^http:\/\//'$url) || preg_match('/^https:\/\//'$url))   
        {  
            
$this->data $url;  
        }  
        else  
        {  
            
$this->data "http://".$url;  
        }  
    }  
      
    
//creating code with bookmark metadata  
    
public function bookmark($title$url){  
        
$this->data "MEBKM:TITLE:".$title.";URL:".$url.";;";  
    }  
      
    
//creating text qr code  
    
public function text($text){  
        
$this->data $text;  
    }  
      
    
//creatng code with sms metadata  
    
public function sms($phone$text){  
        
$this->data "SMSTO:".$phone.":".$text;  
    }  
      
    
//creating code with phone   
    
public function phone_number($phone){  
        
$this->data "TEL:".$phone;  
    }  
      
    
//creating code with mecard metadata  
    
public function contact_info($name$address$phone$email){  
        
$this->data "MECARD:N:".$name.";ADR:".$address.";TEL:".$phone.";EMAIL:".$email.";;";  
    }  
      
    
//creating code wth email metadata  
    
public function email($email$subject$message){  
        
$this->data "MATMSG:TO:".$email.";SUB:".$subject.";BODY:".$message.";;";  
    }  
      
    
//creating code with geo location metadata  
    
public function geo($lat$lon$height){  
        
$this->data "GEO:".$lat.",".$lon.",".$height;  
    }  
      
    
//creating code with wifi configuration metadata  
    
public function wifi($type$ssid$pass){  
        
$this->data "WIFI:T:".$type.";S:".$ssid.";P:".$pass.";;";  
    }  
      
    
//creating code with i-appli activating meta data  
    
public function iappli($adf$cmd$param){  
        
$param_str "";  
        foreach(
$param as $val)  
        {  
            
$param_str .= "PARAM:".$val["name"].",".$val["value"].";";  
        }  
        
$this->data "LAPL:ADFURL:".$adf.";CMD:".$cmd.";".$param_str.";";  
    }  
      
    
//creating code with gif or jpg image, or smf or MFi of ToruCa files as content  
    
public function content($type$size$content){  
        
$this->data "CNTS:TYPE:".$type.";LNG:".$size.";BODY:".$content.";;";  
    }  
      
    
//getting image  
    
public function get_image($size 150$EC_level 'L'$margin '0'){  
        
$ch curl_init();  
        
$this->data urlencode($this->data);   
        
curl_setopt($chCURLOPT_URL'http://chart.apis.google.com/chart');  
        
curl_setopt($chCURLOPT_POSTtrue);  
        
curl_setopt($chCURLOPT_POSTFIELDS'chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data);  
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);  
        
curl_setopt($chCURLOPT_HEADERfalse);  
        
curl_setopt($chCURLOPT_TIMEOUT30);  

        
$response curl_exec($ch);  
        
curl_close($ch);  
        return 
$response;  
    }  
      
    
//getting link for image  
    
public function get_link($size 150$EC_level 'L'$margin '0'){  
        
$this->data urlencode($this->data);   
        return 
'http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data;  
    }  
      
    
//forcing image download 
    
public function download_image($file){ 
        
header('Content-Disposition: attachment; filename=QRcode.png'); 
        
header('Content-Type: image/png'); 
        echo 
$file
    } 
    
    
//save image to server
    
public function save_image($file$path "./QRcode.png"){ 
        
file_put_contents($path$file);
    } 
}  
?>
muchas gracias de antemano.
  #2 (permalink)  
Antiguo 30/01/2017, 13:07
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Implementar QR Code images usando Google Chart API

Solo debes establecer la ruta y el nombre del archivo a guardar

Código PHP:
Ver original
  1. //SALVAR PNG EN SERVIDOR
  2. $file = $qr->get_image();
  3. $path=  './ruta/nombre_archivo.png';
  4. $qr->save_image($file, $path);
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 30/01/2017, 16:00
(Desactivado)
 
Fecha de Ingreso: septiembre-2008
Ubicación: Maracay edo Aragua Venezuela
Mensajes: 48
Antigüedad: 15 años, 7 meses
Puntos: 3
De acuerdo Respuesta: Implementar QR Code images usando Google Chart API

Si de esa manera lo habia intentado pero me estaba generando un error

El archivo guardado en el servidor se leia

http%3A%2F%2Fmiweb.com%2Fbusca%2Fcertificados%2Fin dex.php%3Fbuscar%3DEYA6R082QV

Mientras que el archivo que se descarga de manera manual leia de manera correcta:

http://miweb.com/busca/certificados/...car=EYA6R082QV

Pero me di cuenta que el error estaba en el orden de las sentencias que originaba el error en cuestión. Dejo el codigo por si alguien el agun momento lo necesita, y gracias por responder Triby muy amable de su parte.

Código PHP:
//RUTAS
 
$basedesitio "http://miweb.com/busca/certificados";
 
$inicio '/index.php';
 
$pngqr '/codigosqr';
 
$operador'?buscar=';
// $rutalibqr= '../../../../qr/qrlib.php';
 
$rutalibqr'./qr/qrcode.php';
 
$rutapngqr'./codigosqr/';
 
$webdata $basedesitio$inicio$operador$codigo_generado 
//INCLUYENDO LIBRERIA QR
include  $rutalibqr;
$qr = new qrcode();
//link
$qr->link($webdata);
//SALVAR PNG EN SERVIDOR
    //SALVAR PNG EN SERVIDOR
    
$file $qr->get_image();
    
$path=  $rutapngqr$codigo_generado'.png';
    
$qr->save_image($file$path);
//    $qr->download_image($file);

//$file = $qr->get_image();
//$path=  $rutapngqr;
//$qr->save_image($file, $path);
//MUESTRA QR GENERADO
echo "<p>Link</p>";
echo 
"<p><img src='".$qr->get_link()."' border='0'/></p>"
  #4 (permalink)  
Antiguo 31/01/2017, 20:15
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Implementar QR Code images usando Google Chart API

Según entiendo, estabas usando una URL en lugar de directorio y por eso obtenías el error.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: apis-y-servicios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:05.