<?
// root path to browsable/uploadable directory
// e.g. <a href="http://www.mydomain.com/uploads" target="_blank">http://www.mydomain.com/uploads</a>
$rootURL = "/uploads";
//prefix that appears before file name when browsed for e.g. localhost
// e.g. <a href="http://$URLprefix/uploads/mypic.jpg" target="_blank">http://$URLprefix/uploads/mypic.jpg</a>
$URLprefix = $_SERVER['SERVER_NAME'];
// debug. if true also writes output to a file in executing directory
$debug = false;
//------------------------------------------------------------------------//
// Hello
//
// This is my first attempt at helping with an open source project so
// please bear with me. I've written this connector as i want to use the
// FCKEditor in my site because it will be an excellent piece of software.
// if this helps move things along, brilliant.
//
// This connector handles File browsing & uploading however it does not
// check permissions or if the filename is valid. Please feel free to add
// this yourself if required.
//
// I hope you find this useful.
//
// fatboy
//
// <a href="mailto:fatFCK@code247.com" target="_new">fatFCK@code247.com</a>
//
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
// START OF FUNCTIONS
//------------------------------------------------------------------------//
// returns xml folders node
function list_folders($dir_name)
{
$dir_name = ".".$dir_name;
$dir = opendir($dir_name);
$dir_list = array();
while ($file_name = readdir($dir)) {
if ( ($file_name != ".") && ($file_name != "..") ) {
$find = $dir_name."/".$file_name;
if(is_dir($find))
array_push($dir_list,$file_name);
};
};
closedir($dir);
sort($dir_list);
$dirs = "<Folders>\n";
while (list($key,$value) = each($dir_list)) {
$dirs .= "\t<Folder name=\"".$value."\"/>\n";
};
$dirs .= "</Folders>";
return $dirs;
};
// returns xml files node
function list_files($dir_name,$resourceType)
{
$allow_ext = "gif,jpeg,jpg,png,bmp,swf,wav,mp3,wma,xls,doc,txt,ppt,xml";
switch($resourceType){
case "Image": $allow_ext = "gif,jpeg,jpg,png,bmp";
break;
case "Flash": $allow_ext = "swf";
break;
case "Media": $allow_ext = "wav,mp3,wma";
break;
} // switch
$dir_name = ".".$dir_name;
$dir = opendir($dir_name);
$file_list = array();
while ($file_name = readdir($dir)) {
if ( ($file_name != ".") && ($file_name != "..") ) {
$find = $dir_name."/".$file_name;
if(!is_dir($find))
{
$add = false;
$extension = pathinfo($find);
$extension = $extension[extension];
$allowed_extensions = explode(",", $allow_ext);
for($i = 0; $i < count($allowed_extensions); $i++) {
if($allowed_extensions[$i] == "$extension")
{
$add = true;
break;
}
}
if($add)
array_push($file_list,$file_name."^".(ceil(filesize($find)/1024)));
}
};
};
closedir($dir);
sort($file_list);
$files = "<Files>\n";
while (list($key,$value) = each($file_list)) {
list($name,$size) = split('[\^]',$value);
$files .= "\t<File name=\"".$name."\" size=\"$size\"/>\n";
};
$files .= "</Files>";
return $files;
};
function GetFoldersAndFiles($dir, $baseURL, $resourcetype)
{
$xml = "<?xml version='1.0' encoding='utf-8'?>\n";
$xml = "<?xml version='1.0' encoding='utf-8'?>\n";
$xml = "<?xml version='1.0' encoding='utf-8'?>\n";
$html .= "<HTML><HEAD><TITLE></TITLE></HEAD><BODY><script type=\"text/javascript\">";
$html .= "window.parent.frames['frmUpload'].OnUploadCompleted($result);";
$html .= "</script></BODY></HTML>";
PHP Connector - sorry wrong version try this
$xml = "<?xml version='1.0' encoding='utf-8'?>\n";$xml = "<?xml version='1.0' encoding='utf-8'?>\n";PHP Connector - first attempt
http://www.code247.com/connector
RE: PHP Connector - first attempt
Thanks for this nice peace of code. I'll take a look on it and I hope I can include it in the next beta.
Best regards,
FredCK
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn
RE: PHP Connector - first attempt
I just got started with FCK and PHP. Managed to customize most of it to my wishes, but I understand that I need this PHP connector in order to get file uploads working. Seems like magic.
So, I am not really sure how to get started here. Here's what I did so far (without any results however): I put your connector.php in /fckeditor/editor/filemanager/browser/default/connectors/php. Next, in the fckconfig.js file I changed the lines under the comment 'Link Browsing' as follows:
FCKConfig.LinkBrowser = true ;
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/php/connector.php" ;
So far OK right?
Then, in connector.php, I set
$rootURL = "/kt/uploads";
(kt is an alias for a directory somewhere in the Win XP My Documents folder - a yes, I'm testing locally on XP, PHP 4.3 - but that alias should work fine I guess)
Next, when I enable debugging in your php file, I see an output.htm in the php directory. It says:
<Connector command="GetFoldersAndFiles" resourceType="Media" stamp="1087509449">
<CurrentFolder path="/" url="localhost/kt/uploads/" />
<Folders>
</Folders>
<Files>
</Files>
</Connector>
Could you give me any hints?
RE: PHP Connector - first attempt
... Filebrowser ... did i miss something? Allready in Version 1.x?
When i look at at the *.php in the filebrowser-Folder of Version 1.x, i see a simple litte Uploader-Script (and a FileLister ... )
What you have coded above is a great deal more!
But i'm missing a clear interface. It's just a bunch of Functions.
That's something i allready missed in Version 1.x. An Object oriented Approach in Creating, Configuring and Fetching the Editor. It was there, but it was too small. Too many thing were to be done elsewhere.
I'm planning on making a connector as element in PEAR::HTML_Quickform. I won't touch the Filebrowser, since you are doing some promising things here.
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt
The reason was the dir_name variabel started with a .. and the code added another . so the folder was not found ... I added a handeler for this...
Replace:
$dir_name = ".".$dir_name;
With :
if(substr($dir_name,0,1) != ".") $dir_name = ".".$dir_name;
Do this on Line 41 and 74
And it works...
BR
Martin Kronstad
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt
http://www.siteman.no/martin/connector.zip
RE: PHP Connector - first attempt
Isnt that starange? Anyone else having this problem?
RE: [johannesf] PHP Connector - first attempt
chmod($uniqueName, 0644);
With this, ur files will be deletable under a linux/unix web shared system.
Hope this will help,
Simon [Fr] ^^
RE: PHP Connector - first attempt
I also tried this efter:
if (move_uploaded_file($_FILES['NewFile']['tmp_name'],$uniqueName) ) {
here:
$oldMask = umask(0);
chmod($uniqueName, 0644);
umask($oldMask);
but still I cant delete the files, I use Linux on the server.
Tip:
on row 166
if(!mkdir($newfldr, 0775))
to mekae me delete the folders
RE: PHP Connector - first attempt
http://sourceforge.net/forum/forum.php? ... _id=379487
RE: PHP Connector - first attempt
Well, I have doone a script that delete them som it ok for the moment, but still I cant understand why It wont work for mee.
It would be nice to have a "deletebotton" int the filemanager!
/jof
RE: PHP Connector - first attempt
Maybe 0775 is not enough for directory and you have to use 0777 to access to its content.
Greetings,
Andreas.
RE: PHP Connector - first attempt
Thanks
Jake
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt
RE: PHP Connector - first attempt