This is a migrated thread and some comments may be shown as answers.

ImageBrowser implementation in PHP

1 Answer 116 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Wes Cloven
Top achievements
Rank 2
Wes Cloven asked on 28 Jan 2013, 08:47 PM
I am struggling to get the image browser to work in php.  One thing that always stumps me with the documentation is finding the schema that is expected via json.  After viewing a .NET MVC example I came up with the following.  It isn't working yet but was hoping for some direction.

Right now with the following code the image browser comes up with the busy animation in the center and nothing happens beyond that.

File: obj.file.php
<?PHP
class FileObj {
    public $name = "";
    public $type = "";
    public $size = "";
}
?>
File: read.php
<?
include_once("obj.file.php");
 
$path = $_GET["path"];
$serverFilePath = "/home/midmosou/public_html/";
$filter = "*.*";
 
if(is_dir($serverFilePath . $path))
{
    foreach (glob($serverFilePath . $path . $filter) as $filename) {
        $file = new FileObj();
 
        if (is_dir($filename))
        {
            $file->name = basename($filename);
            $file->type = "d";
            $file->size = "0";
        } else {
            $file->name = basename($filename);
            $file->type = "f";
            $file->size = filesize($filename);
        }
 
        $data[] = $file;
    }
 
    $count = count($data);
    echo "{\"data\":" .json_encode($data). ", \"count\":" . json_encode($count) . "}";
}
?>
This returns data similar to:
{"data":[{"name":"FaceBook.png","type":"f","size":1331},{"name":"School_dance.jpg","type":"f","size":13576},{"name":"bbb-logo.jpg_600.jpg","type":"f","size":38843},{"name":"bbb_96.gif","type":"f","size":1320},{"name":"blogger_logo.jpg","type":"f","size":18175},{"name":"fztp020w_1.jpg","type":"f","size":46205},{"name":"live_sound_mo.jpg","type":"f","size":22116},{"name":"live_sound_system_rental_mo.jpg","type":"f","size":10794},{"name":"search-engine-optimization_102.png","type":"f","size":18850},{"name":"sound-main-mid-mo.jpg","type":"f","size":29101},{"name":"sound_man_1.jpg","type":"f","size":11412}], "count":11}
The editor declaration code looks like the following.  This has gone through several experimental edits so hopefully it is close.
<textarea id="editor1" id="page_body" name="page_body" style="width: 100%; height: 300px;"><? echo $page_body;?></textarea>
 
<script>
    $(document).ready(function() {
        $("#editor1").kendoEditor({
             encoded: false,
             imageBrowser: {
                transport: {
                    read: "/includes/kendoui/service/imagebrowser/read.php",
                    destroy: {
                        url: "/includes/kendoui/service/imagebrowser/destroy.php",
                        type: "POST"
                    },
                    create: {
                        url: "/includes/kendoui/service/imagebrowser/createDirectory.php",
                        type: "POST"
                    },                      imageUrl: "/Company_Images/{0}"
                },
                path: "Company_Images/"
             }
         });
    });
</script>




File: read.php 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 29 Jan 2013, 09:04 AM
Hi Wes,

 You could try returning a regular array as JSON response:

echo json_encode($data);

This is the default response expected by the image browser - array of objects representing the files and directories. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Editor
Asked by
Wes Cloven
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Share this question
or