0

I have a table with two fields:

1) folder: with the folder path;

2) name: the name of png files

With php code I need to take all the complete path (example frames/1.png and frames/2.png) and with this Path I need to get the real image and insert their in an array as if they were all blobs.

at the moment I use this code but with this I have only the path and not the real image. can you help me please?

<?php

    require("db.php");

    session_start();

    $sql = "SELECT concat('C:/wamp/www/Tecnitalia_Optic/app/webroot/img/',folder, thumb) as    mini FROM frames ";

    $result = array();

    if ($resultdb = $mysqli->query($sql)) {

        while($record = $resultdb->fetch_assoc()) {
            array_push($result, $record);
        }   

        $resultdb->close();
    }


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


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

?>
Serpiton
  • 3,676
  • 3
  • 24
  • 35
Carlo
  • 39
  • 6

2 Answers2

0
<?php
require("db.php");
session_start();
$sql = "SELECT concat('C:/wamp/www/Tecnitalia_Optic/app/webroot/img/',folder, thumb) as mini FROM frames ";
$result = array();
if ($resultdb = $mysqli->query($sql)) {
    while($record = $resultdb->fetch_assoc()) {
        array_push($result, file_get_contents($record['mini']));
    }
    $resultdb->close();
}
//send back information to extjs
echo json_encode(array(
    "success" => $mysqli->connect_errno == 0,
    "data" => $result
)); 
/* close connection */
$mysqli->close();

See: http://www.php.net/manual/fr/function.file-get-contents.php

Related question: Displaying pictures from path in PHP from MySQL

Community
  • 1
  • 1
punkeel
  • 869
  • 8
  • 12
0

What you are storing in the table is the entire absolute path to the image.

'C:/wamp/www/Tecnitalia_Optic/app/webroot/img/'

What you should do instead, is to just store the relative path from where you PHP script is located. So, if your PHP script is in the webroot folder, the path would be just:

'img/'

With this the result should provide you the output of: 'img/folder/thumb.png'

If it doesn't work, you can debug by displaying the contents of what exactly is being returned by the $result:

/*echo json_encode(array(
    "success" => $mysqli->connect_errno == 0,
    "data" => $result
));*/ 

var_dump($result)
Prahlad Yeri
  • 3,567
  • 4
  • 25
  • 55