Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Touch - the Store don't read my php file

  1. #1
    Sencha User
    Join Date
    Jun 2014
    Posts
    58
    Answers
    6

    Default Answered: Touch - the Store don't read my php file

    I have problem to read my php file with the Store. I think that the problem is the base64_encode command in php file.
    I Explain it. In my php, I take a path with sql code and after, with this path, I get the real image. After I need to give the results saved in an array, to sencha architect.
    This is php Code:

    PHP Code:
        require("db.php");
    session_start();
    $filepath='';
    $sql "SELECT concat('C:/wamp/www/Tecnitalia_Optic/app/webroot/img/',folder) as Path, thumb as FileName FROM frames ";
    $result = array();
    if (
    $resultdb $mysqli->query($sql)) {
        while(
    $record $resultdb->fetch_array()) {                $filepath $record['Path'];        $nomeFile $record['FileName'];        $mimetype pathinfo($nomeFilePATHINFO_EXTENSION);        $filedata=filesize($filepath."/".$nomeFile);        header('Content-Type: '.$mimetype);        header('Content-Disposition: attachment; filename="'.$nomeFile.'"');        header('Content-Transfer-Encoding: binary');                header('Content-Length: '.sprintf('%d'$filedata));        header('Expires: 0');        //readfile($filepath."/".$nomeFile);        $recordnew = readfile($filepath."/".$nomeFile);        $result[] = $recordnew;    }    
        
    $resultdb->close();}

    //count total records from table for paging$sql = "SELECT count(*) as num FROM frames ";
    $total 0;if ($resultdb $mysqli->query($sql)) {
        
    $record $resultdb->fetch_assoc();        $total $record['num'];
        
    $resultdb->close();}
    //send back information to sencha architect touchecho json_encode(array(    "success" => $mysqli->connect_errno == 0,    "total" => $total,    "data" => base64_encode($result)));    

    /* close connection */
    $mysqli->close(); 
    after that, in SA I have created a model with one field with type auto. After I have created a Json Store link with the model but the store say me this: MyJsonReader unable to read data. Open in Browser: api/frames.php

    This is my sencha architect code:

    Model

    Code:
    
    
    Code:
    Ext.define('ciaopoint2.model.frames', {
        extend: 'Ext.data.Model',
    
    
        requires: [
            'Ext.data.Field'
        ],
    
    
        config: {
            fields: [
                {
                    name: 'mini',
                    type: 'auto'
                }
            ]
        }
    });


    Store

    Code:
    
    
    Code:
    Ext.define('ciaopoint2.store.Frames', {
        extend: 'Ext.data.Store',
        alias: 'store.frames',
    
    
        requires: [
            'ciaopoint2.model.frames',
            'Ext.data.proxy.Ajax',
            'Ext.data.reader.Json'
        ],
    
    
        config: {
            autoLoad: true,
            model: 'ciaopoint2.model.frames',
            storeId: 'Frames',
            proxy: {
                type: 'ajax',
                url: 'api/frames.php',
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                }
            }
        }
    });


  2. Carlo,

    ignore my previous post.

    I think I found the problem:

    readfile($filepath."/".$nomeFile)

    returns the file size (the number of bytes read), not the file content, and you are base64_encoding that value, presumably always the same value.

    In order to read images files in php look at the following link:

    http://www.php.net/manual/en/book.image.php#93393


    Dario

  3. #2
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    27

    Default

    I haven't worked on touch based project for sometime but I think there's few things you can try. First, you said you put the results in an array, so try use an array reader instead of the json reader. Second, I remember the model needs to know which field should be used as the id field. So you might want to add a id field associated with the image.

  4. #3
    Sencha User
    Join Date
    Jun 2014
    Posts
    58
    Answers
    6

    Default

    Thank, I try. Can you explain me the second thingh please about the Id Field?

  5. #4
    Sencha Premium Member
    Join Date
    Jan 2013
    Posts
    27

    Default

    below is a screen shot I took from my ExtJs project but Touch project should have this too.
    Capture4.PNG

  6. #5
    Sencha User
    Join Date
    Jun 2014
    Posts
    58
    Answers
    6

    Default

    I tried what did you say but nothing...with an Id nothing changes

  7. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    9,488
    Answers
    74

    Default

    What does the generated JSON look like that comes out of the PHP? Is it valid?

  8. #7
    Sencha User
    Join Date
    Jun 2014
    Posts
    58
    Answers
    6

    Default

    If I launch the php on the browser I Obtain this:

    {"success":true,"total":"3","
    data":[{"id":"15","piccolo":"NDA2MDU=","grande":"MTA4MjM5NQ=="},{"id":"16","piccolo":"NDA2MDU=","grande":"MTA4MjM5NQ=="},{"id":"17","piccolo":"NDA2MDU=","grande":"MTA4MjM5NQ=="}]}

    I don't know if is corret because inside the field 'piccolo' and the field 'grande' i see always the same write (I don't know if is a base64_encode routine...)
    I attached my complete php file (is different from the other). For you is correct to use base64_encode?

    PHP Code:
        require("db.php");
    session_start();

    $filepath='';
    $i 0;
    $sql "SELECT id, concat('C:/wamp/www/Tecnitalia_Optic/app/webroot/img/',folder) as Path, thumb as FileNameP, file as FileNameG FROM frames ";

    $result = array();

    if (
    $resultdb $mysqli->query($sql)) {
        while(
    $record $resultdb->fetch_array()) {                
        
    $filepath $record['Path'];        
        
    $nomeFile $record['FileNameP'];                
        
    $mimetype pathinfo($nomeFile,PATHINFO_EXTENSION);        
        
    $filedata=filesize($filepath."/".$nomeFile);        h
        header
    ('Content-Type: '.$mimetype);       
        
    header('Content-Disposition: attachment; filename="'.$nomeFile.'"');        
        
    header('Content-Transfer-Encoding: binary');                
       
    header('Content-Length: '.sprintf('%d'$filedata));        
       
    header('Expires: 0');                        

    $result[$i]['id'] = $record['id'];        
    $result[$i]['piccolo'] = base64_encode(readfile($filepath."/".$nomeFile));     
      
        
    $nomeFile $record['FileNameG'];                
        
    $mimetype pathinfo($nomeFilePATHINFO_EXTENSION);        
        
    $filedata=filesize($filepath."/".$nomeFile);        
        
    header('Content-Type: '.$mimetype);       
        
    header('Content-Disposition: attachment; filename="'.$nomeFile.'"');        
        
    header('Content-Transfer-Encoding: binary');                
        
    header('Content-Length: '.sprintf('%d'$filedata));        
        
    header('Expires: 0');                    
         
    $result[$i]['grande'] = base64_encode(readfile($filepath."/".$nomeFile));
         
        
    $i++;                    
    }    
        
    $resultdb->close();}

    //count total records from table for paging
    $sql "SELECT count(*) as num FROM frames ";
    $total 0;if ($resultdb $mysqli->query($sql)) {
        
    $record $resultdb->fetch_assoc();        
       
    $total $record['num'];
        
    $resultdb->close();}

    //send back information to sencha architect touch
    echo json_encode(array(    
    "success" => $mysqli->connect_errno == 0,    
    "total" => $total,   
     
    "data" => $result));    

    /* close connection */$mysqli->close(); 

  9. #8
    Sencha Premium User
    Join Date
    Jan 2014
    Location
    Italy
    Posts
    116
    Answers
    5

    Default

    Carlo,

    did you check that after each read :

    Code:
    while($record = $resultdb->fetch_array()) {
        $filepath = $record['Path'];        
        $nomeFile = $record['FileNameP'];
        ........

    $filePath and $nomeFile contain different values ?

    Maybe you are reading images always from the same file.

    Ciao,
    Dario
    Last edited by faireu; 4 Jul 2014 at 12:31 AM. Reason: Clarify

  10. #9
    Sencha Premium User
    Join Date
    Jan 2014
    Location
    Italy
    Posts
    116
    Answers
    5

    Default

    Carlo,

    ignore my previous post.

    I think I found the problem:

    readfile($filepath."/".$nomeFile)

    returns the file size (the number of bytes read), not the file content, and you are base64_encoding that value, presumably always the same value.

    In order to read images files in php look at the following link:

    http://www.php.net/manual/en/book.image.php#93393


    Dario

  11. #10
    Sencha User
    Join Date
    Jun 2014
    Posts
    58
    Answers
    6

    Default

    Dario, excuse me...i'm a beginner. Can you write me a small example of how would you do it or how would you modify my php script?

    thank you

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •