Explorer-like frontend add-on to upload/download.
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Thu Jul 01, 2010 6:12 am
hi how are you? I have a problem with the installation of jdiskexplorer, first to clarify that even do not buy any version and I am doing tests on my local pc, to see if I need, but I can not make it work, as always in the quadrant remote server shows me the original folder on my server in my case C: / /, I want to know if that does not purchase the license or because I am doing something wrong .. I want to work with php as server-side language
so did the include of explorer.php in process.php
Code: Select all
function emu_getallheaders()
{
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
$headers[$hp[1]]=$v;
return $headers;
}
include "explorer.php";
so that the variable $ upload_dir
Code: Select all
$upload_dir = 'C:/Archivos de programa';
this is the tree from my server
so is the code of my applet_http_explorer.js
Code: Select all
<!--
var _info = navigator.userAgent;
var _ns = false;
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
if (_info.indexOf("Opera") > 0) _ie = false;
var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) || (_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0) || (_info.indexOf("IRIX") > 0)));
var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));
if (_ie == true) {
document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH="768" HEIGHT="320" NAME="fileupload" codebase="http://java.sun.com/update/1.4.2/jinstall-1_4-windows-i586.cab#Version=1,4,0,0">');
}
else if (_ns == true && _ns6 == false) {
// BEGIN: Update parameters below for NETSCAPE 3.x and 4.x support.
document.write('<EMBED ');
document.write('type="application/x-java-applet;version=1.4" ');
document.write('CODE="jfileupload.upload.client.MApplet.class" ');
document.write('JAVA_CODEBASE="./" ');
document.write('ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/explorerui.jar" ');
document.write('NAME="fileupload" ');
document.write('WIDTH="768" ');
document.write('HEIGHT="320" ');
document.write('url="http://localhost/gaby/ftp2/explorer.php" ');
document.write('paramfile="uploadfile" ');
document.write('param1="todo" ');
document.write('value1="upload" ');
document.write('param2="relativefilename" ');
document.write('value2="true" ');
document.write('param3="emptydirectory" ');
document.write('value3="true" ');
document.write('folderdepth="-1" ');
document.write('sm="enabled" ');
document.write('encoding="ISO-8859-1" ');
document.write('transferui="jfileupload.transfer.client.explorer.ExplorerTransferUI" ');
document.write('resources="i18n_bar" ');
document.write('transferuiresources="i18n_pane" ');
document.write('mode="http" ');
document.write('scriptable=true ');
document.writeln('pluginspage="http://java.sun.com/products/plugin/index.html#download"><NOEMBED>');
// END
}
else {
document.writeln('<APPLET CODE="jfileupload.upload.client.MApplet.class" JAVA_CODEBASE="./" ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/explorerui.jar" WIDTH="768" HEIGHT="320" NAME="fileupload">');
}
// BEGIN: Update parameters below for INTERNET EXPLORER, FIREFOX, SAFARI, OPERA, MOZILLA, NETSCAPE 6+ support.
document.writeln('<PARAM NAME=CODE VALUE="jfileupload.upload.client.MApplet.class">');
document.writeln('<PARAM NAME=CODEBASE VALUE="./">');
document.writeln('<PARAM NAME=ARCHIVE VALUE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar,lib/explorerui.jar">');
document.writeln('<PARAM NAME=NAME VALUE="fileupload">');
document.writeln('<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">');
document.writeln('<PARAM NAME="scriptable" VALUE="true">');
document.writeln('<PARAM NAME="url" VALUE="http://localhost/gaby/ftp2/explorer.php">');
document.writeln('<PARAM NAME="paramfile" VALUE="uploadfile">');
document.writeln('<PARAM NAME="param1" VALUE="todo">');
document.writeln('<PARAM NAME="value1" VALUE="upload">');
document.writeln('<PARAM NAME="param2" VALUE="relativefilename">');
document.writeln('<PARAM NAME="value2" VALUE="true">');
document.writeln('<PARAM NAME="param3" VALUE="emptydirectory">');
document.writeln('<PARAM NAME="value3" VALUE="true">');
document.writeln('<PARAM NAME="folderdepth" VALUE="-1">');
document.writeln('<PARAM NAME="sm" VALUE="enabled">');
document.writeln('<PARAM NAME="encoding" VALUE="ISO-8859-1">');
document.writeln('<PARAM NAME="transferui" VALUE="jfileupload.transfer.client.explorer.ExplorerTransferUI">');
document.writeln('<PARAM NAME="resources" VALUE="i18n_bar">');
document.writeln('<PARAM NAME="transferuiresources" VALUE="i18n_pane">');
document.writeln('<PARAM NAME="mode" VALUE="http">');
// END
if (_ie == true) {
document.writeln('</OBJECT>');
}
else if (_ns == true && _ns6 == false) {
document.writeln('</NOEMBED></EMBED>');
}
else {
document.writeln('</APPLET>');
}
//-->
this is what I see when running applet_http_explorer.html
As you can see in the left pane is showing me c: / / when should show c: / / wamp/www/gaby/ftp2/up
I want to clarify that I am interested in buying the license .. but first I would like to do some tests to see if they are what my client needs .. .. and I have to modify the javascript .. to process folders .. dynamically as session variables
from already thank you very much for everything
support
Posts: 1503 Joined: Sun Jan 27, 2008 6:19 pm
Post
by support » Thu Jul 01, 2010 5:29 pm
I think there is a problem in explorer.php in list command:
Try to dump in a file what is returning:
Code: Select all
// Process filesystem command.
if ($cmdStr == "list")
{
$dirStr = $val1;
if ($dirStr != "")
{
print("\n");
print("<pre>\n");
if ($dh = opendir($dirStr))
{
while (($file = readdir($dh)) !== false)
{
if ($file == "." || $file == "..") continue;
$date = fileatime($dirStr."/".$file);
$name = basename($dirStr."/".$file);
$size = filesize($dirStr."/".$file);
$type = "file";
if (is_dir($dirStr."/".$file)) $type = "dir";
print($type." ".$date." ".$size." ".$name."<br>\n");
}
closedir($dh);
}
print("</pre>\n");
exit;
}
}
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Thu Jul 01, 2010 8:26 pm
Thanks for your kind answer, look I'll explain .. I had to tweak the code to bring me something
i Paste the code at the end of process.php, that the original code
Code: Select all
// Process filesystem command.
if ($cmdStr == "list")
{
$dirStr = $val1;
if ($dirStr != "")
{
print("\n");
print("<pre>\n");
if ($dh = opendir($dirStr))
{
while (($file = readdir($dh)) !== false)
{
if ($file == "." || $file == "..") continue;
$date = fileatime($dirStr."/".$file);
$name = basename($dirStr."/".$file);
$size = filesize($dirStr."/".$file);
$type = "file";
if (is_dir($dirStr."/".$file)) $type = "dir";
print($type." ".$date." ".$size." ".$name."<br>\n");
}
closedir($dh);
}
print("</pre>\n");
exit;
}
}
and this is a custom code
Code: Select all
<?php
$cmdStr='list';
//$val1='up';
if ($cmdStr == "list")
{
$dirStr = $upload_dir;
if ($dirStr != "")
{
print("\n");
print("<pre>\n");
//I saw that the variable $ dh was not defined .. and assume that you could be wrong .. as it does if the opendir
$dh = opendir($dirStr);
while (($file = readdir($dh)) !== false)
{
if ($file == "." || $file == "..") continue;
$date = fileatime($dirStr."/".$file);
$name = basename($dirStr."/".$file);
$size = filesize($dirStr."/".$file);
$type = "file";
if (is_dir($dirStr."/".$file)) $type = "dir";
print($type." ".$date." ".$size." ".$name."<br>\n");
}
closedir($dh);
print("</pre>\n");
exit;
}
}
?>
otherwise would not throw me anything
and this gives me file
file 1278014656 251338 dock.zip
which is correct .. but when tested with the. jar, it does not work .. is but I'm not sure doing the right thing ..
from and appreciate your help
support
Posts: 1503 Joined: Sun Jan 27, 2008 6:19 pm
Post
by support » Fri Jul 02, 2010 2:53 pm
Could you provide a link to your JDiskExplorer installation?
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Sat Jul 03, 2010 4:21 am
hello thank you for your prompt response, the link is
http://www.grupobeck.com.mx/javier
my code is process.php
Code: Select all
<?php
$upload_dir = $_SERVER['DOCUMENT_ROOT']."/javier/up/";
$max_size = 1500000;
$createsubfolders = "true";
$keepalive = "false";
$resume = "false";
if ($resume == "true")
{
ignore_user_abort(TRUE);
}
//set_time_limit(0);
error_reporting(0);
$message ="";
if (!is_dir($upload_dir))
{
if (!recursiveMkdir($upload_dir)) die ("cannot access upload directory");
if (!chmod($upload_dir,0755)) die ("change permission to 755 failed.");
}
$REQUEST_METHOD=$_SERVER["REQUEST_METHOD"];
$headers = emu_getallheaders();
if ($REQUEST_METHOD=="HEAD")
{
$filename = "";
if (isset($headers['RELATIVEFILENAME']))
{
$filename = $headers['RELATIVEFILENAME'];
}
else
{
if (isset($headers['FILENAME']))
{
$filename = $headers['FILENAME'];
}
}
if(get_magic_quotes_gpc()) $filename = stripslashes($filename);
if ($filename != "")
{
if ($keepalive == "false")
{
header("Connection: close");
}
$account = "";
if (isset($headers['ACCOUNT']))
{
$account = $headers['ACCOUNT'];
if (substr($account,0,1) != "/") $account = "/".$account;
}
$fhead=$upload_dir.$account."/".$filename;
$fhead = str_replace("\\","/",$fhead);
if (file_exists($fhead))
{
header("size: ".filesize($fhead));
}
else header("HTTP/1.1 404");
}
}
// PUT upload support.
if ($REQUEST_METHOD=="PUT")
{
if ((isset($headers['TODO'])) && ($headers['TODO']=="upload"))
{
$account = "";
if (isset($headers['ACCOUNT']))
{
$account = $headers['ACCOUNT'];
if (substr($account,0,1) != "/") $account = "/".$account;
}
$target_folder=$upload_dir.$account;
if (isset($headers['ACCOUNTCREATION']))
{
if ($headers['ACCOUNTCREATION'] == "true") recursiveMkdir($target_folder);
}
$relative = $headers['RELATIVEFILENAME'];
$file_name = $headers['FILENAME'];
if(get_magic_quotes_gpc())
{
$relative = stripslashes($relative);
$file_name = stripslashes($file_name);
}
if (($createsubfolders == "true") && ($relative != ""))
{
$inda=strlen($relative);
$indb=strlen($file_name);
if (($indb > 0) && ($inda > $indb))
{
$subfolder = substr($relative,0,($inda-$indb)-1);
$subfolder = str_replace("\\","/",$subfolder);
$target_folder = $upload_dir.$account."/".$subfolder;
recursiveMkdir($target_folder);
}
}
if ($file_name == "") $file_name = "put.bin";
$message = do_put_upload($target_folder,$file_name,$max_size,$resume);
}
}
// POST upload support.
if ($_POST['todo']=="upload")
{
$account = "";
if (isset($_POST['account']))
{
$account = $_POST['account'];
if (substr($account,0,1) != "/") $account = "/".$account;
}
$target_folder=$upload_dir.$account;
if (isset($_POST['accountcreation']))
{
if ($_POST['accountcreation'] == "true") recursiveMkdir($target_folder);
}
// relalivefilename support for folders and subfolders creation.
$relative = $_POST['relativefilename'];
if(get_magic_quotes_gpc()) $relative = stripslashes($relative);
if (($createsubfolders == "true") && ($relative != ""))
{
$file_name = $_FILES['uploadfile']['name'];
if(get_magic_quotes_gpc()) $file_name = stripslashes($file_name);
$inda=strlen($relative);
$indb=strlen($file_name);
if (($indb > 0) && ($inda > $indb))
{
$subfolder = substr($relative,0,($inda-$indb)-1);
$subfolder = str_replace("\\","/",$subfolder);
$target_folder = $upload_dir.$account."/".$subfolder;
recursiveMkdir($target_folder);
}
}
if ($_FILES['uploadfile'])
{
if ($keepalive == "false")
{
header("Connection: close");
}
$message = do_post_upload($target_folder,$max_size,$resume);
// Recompose file from chunks (if any).
$chunkid = $_POST['chunkid'];
$chunkamount = $_POST['chunkamount'];
$chunkbaseStr = $_POST['chunkbase'];
if(get_magic_quotes_gpc()) $chunkbaseStr = stripslashes($chunkbaseStr);
if (($chunkid != "") && ($chunkamount != "") && ($chunkbaseStr != ""))
{
if ($chunkid == $chunkamount)
{
// recompose file.
$fname = $target_folder."/".$chunkbaseStr;
if (file_exists($fname)) $fname = $fname.".".time();
$fout = fopen ($fname, "wb");
for ($c=1;$c<=$chunkamount;$c++)
{
$filein = $target_folder."/".$chunkbaseStr.".".$c;
$fin = fopen ($filein, "rb");
while (!feof($fin))
{
$read = fread($fin,4096);
fwrite($fout,$read);
}
fclose($fin);
unlink($filein);
}
fclose($fout);
}
}
}
else
{
$emptydirectory = $_POST['emptydirectory'];
if ($emptydirectory != "")
{
recursiveMkdir($upload_dir.$account."/".$emptydirectory);
}
$message = "No uploaded file(s).";
}
}
function do_post_upload($upload_dir,$max_size,$resume_enabled)
{
$temp_name = $_FILES['uploadfile']['tmp_name'];
$file_name = $_FILES['uploadfile']['name'];
$file_size = $_FILES['uploadfile']['size'];
$file_type = $_FILES['uploadfile']['type'];
$file_error = $_FILES['uploadfile']['error'];
if(get_magic_quotes_gpc()) $file_name = stripslashes($file_name);
//$file_name = str_replace("\\","/",$file_name);
$file_path = $upload_dir."/".$file_name;
// Check filename.
if ($file_name =="")
{
$message = "Error - Invalid filename";
return $message;
}
// Check file size.
if ($file_size > $max_size)
{
$errormsg = "- File size is over ".$max_size." bytes";
header("HTTP/1.1 405");
header("custommessage: ".$errormsg);
$message = "Error ".$errormsg;
return $message;
}
$result = FALSE;
if (($resume_enabled == "true") && (file_exists($file_path)) && (isset($_SERVER['HTTP_CONTENT_RANGE'])))
{
// Resume support.
$range_header = $_SERVER['HTTP_CONTENT_RANGE'];
if (substr($range_header,0,6) == 'bytes ')
{
$minus = strpos($range_header,'-');
$start_offset = substr($range_header,6,$minus-6);
$file_path_tmp = $file_path.".".$start_offset.".".time();
$result = move_uploaded_file($temp_name, $file_path_tmp);
$fout = fopen ($file_path, "rb+");
fseek ($fout,$start_offset);
$fin = fopen ($file_path_tmp, "rb");
while (!feof($fin))
{
$read = fread($fin,4096);
fwrite($fout,$read);
}
fclose($fin);
unlink($file_path_tmp);
fclose($fout);
}
}
else
{
// Regular upload.
$result = move_uploaded_file($temp_name, $file_path);
}
if ($result)
{
chmod($file_path,0755);
$message = "$file_name uploaded successfully.";
return $message;
}
else
{
$errormsg = "- PHP upload failed";
header("HTTP/1.1 405");
header("custommessage: ".$errormsg);
$message = "Error ".$errormsg;
return $message;
}
}
function do_put_upload($upload_dir,$file_name,$max_size,$resume_enabled)
{
$file_path = $upload_dir."/".$file_name;
// Check filename.
if ($file_name =="")
{
$message = "Error - Invalid filename";
return $message;
}
// Check file size.
$file_size = $_SERVER['CONTENT_LENGTH'];
if ($file_size > $max_size)
{
$errormsg = "- File size is over ".$max_size." bytes";
header("HTTP/1.1 405");
header("custommessage: ".$errormsg);
$message = "Error ".$errormsg;
return $message;
}
$result = FALSE;
$start_offset = 0;
$woption = "wb";
if (($resume_enabled == "true") && (file_exists($file_path)) && (isset($_SERVER['HTTP_CONTENT_RANGE'])))
{
// Resume support.
$range_header = $_SERVER['HTTP_CONTENT_RANGE'];
if (substr($range_header,0,6) == 'bytes ')
{
$minus = strpos($range_header,'-');
$start_offset = substr($range_header,6,$minus-6);
$woption = "rb+";
}
}
$putdata = fopen("php://input","r");
$fout = fopen ($file_path, $woption);
if ($start_offset > 0) fseek ($fout,$start_offset);
while (!feof($putdata))
{
$read = fread($putdata,4096);
fwrite($fout,$read);
}
$result = fclose($fout);
fclose($putdata);
if ($result)
{
chmod($file_path,0755);
$message = "$file_name uploaded successfully.";
return $message;
}
else
{
$errormsg = "- PHP upload failed";
header("HTTP/1.1 405");
header("custommessage: ".$errormsg);
$message = "Error ".$errormsg;
return $message;
}
}
function recursiveMkdir($path)
{
if (!file_exists($path))
{
recursiveMkdir(dirname($path));
echo mkdir($path, 0755);
}
else return true;
}
function emu_getallheaders()
{
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
$headers[$hp[1]]=$v;
return $headers;
}
include "explorer.php";
?>
<html>
<head>
<title>Upload file: PHPScript sample</title>
</head>
<body>
<center>
<br>
<? echo $message ?>
<form action="process.php" method="post" ENCTYPE="multipart/form-data" name="upload" id="upload">
Select file to upload :
<input type="hidden" name="todo" value="upload">
<input type="file" name="uploadfile">
<input type="submit" name="upload" value="Upload">
<p> </p>
<p> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><font size="-1" face="Courier New, Courier, mono"><a href="http://www.jfileupload.com" target="_blank">JFileUpload</a></font></p>
</form>
</center>
</body>
</html>
My code is .. explorer.php
Code: Select all
<?php
$allowabsolute = "false";
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$cmdStr = $_POST['cmd'];
if ($cmdStr != "")
{
// Check input parameters.
$val1 = $_POST['val1'];
if ($val1 != "")
{
if(get_magic_quotes_gpc()) $val1 = stripslashes($val1);
if ($allowabsolute == "false")
{
if ((substr_count($val1, "/..")>0) || (substr_count($val1, "\\..")>0))
{
header("HTTP/1.1 403");
exit;
}
$val1 = $upload_dir.$val1;
}
}
$val2 = $_POST['val2'];
if ($val2 != "")
{
if(get_magic_quotes_gpc()) $val2 = stripslashes($val2);
if ($allowabsolute == "false")
{
if ((substr_count($val2, "/..")>0) || (substr_count($val2, "\\..")>0))
{
header("HTTP/1.1 403");
exit;
}
$val2 = $upload_dir.$val2;
}
}
// Process filesystem command.
if ($cmdStr == "list")
{
$dirStr = $val1;
if ($dirStr != "")
{
print("\n");
print("<pre>\n");
if ($dh = opendir($dirStr))
{
while (($file = readdir($dh)) !== false)
{
if ($file == "." || $file == "..") continue;
$date = fileatime($dirStr."/".$file);
$name = basename($dirStr."/".$file);
$size = filesize($dirStr."/".$file);
$type = "file";
if (is_dir($dirStr."/".$file)) $type = "dir";
print($type." ".$date." ".$size." ".$name."<br>\n");
}
closedir($dh);
}
print("</pre>\n");
exit;
}
}
else if ($cmdStr =="mkdir")
{
$mkdirStr = $val1;
if ($mkdirStr != "")
{
$created = mkdir($mkdirStr);
if ($created === true)
{
header("HTTP/1.1 204");
}
else
{
header("HTTP/1.1 403");
}
exit;
}
}
else if ($cmdStr == "del")
{
$delStr = $val1;
if ($delStr != "")
{
$deleted = false;
if (is_dir($delStr))
{
$deleted = rmdir($delStr);
}
else
{
$deleted = unlink($delStr);
}
if ($deleted === true)
{
header("HTTP/1.1 204");
}
else
{
header("HTTP/1.1 403");
}
exit;
}
}
else if ($cmdStr == "move")
{
$fromStr = $val1;
$toStr = $val2;
if (($fromStr != "") && ($toStr != ""))
{
$renamed = rename($fromStr,$toStr);
if ($renamed === true)
{
header("HTTP/1.1 204");
}
else
{
header("HTTP/1.1 403");
}
exit;
}
}
else if ($cmdStr == "download")
{
if ($keepalive == "false") header("Connection: close");
$fileStr = $val1;
if (($fileStr != "") && ($fileStr != ""))
{
if (file_exists($fileStr)==true)
{
header("Content-Length: ".filesize($fileStr));
$fin = fopen($fileStr, "rb");
while (!feof($fin))
{
$read = fread($fin,4096);
print($read);
flush();
}
fclose($fin);
}
else
{
header("HTTP/1.1 403");
}
exit;
}
}
exit;
}
}
?>
and exploring other so you can see the source code of my page ...
support
Posts: 1503 Joined: Sun Jan 27, 2008 6:19 pm
Post
by support » Sat Jul 03, 2010 9:01 am
It seems to work here except the date. Update the explorer.php to multiply by 1000 the file timestamp. It should be better.
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Sun Jul 04, 2010 5:25 am
sorry but I misunderstood .. ask me to do this?
Code: Select all
if ($cmdStr == "list")
{
$dirStr = $val1;
if ($dirStr != "")
{
print("\n");
print("<pre>\n");
if ($dh = opendir($dirStr))
{
while (($file = readdir($dh)) !== false)
{
if ($file == "." || $file == "..") continue;
$date = fileatime($dirStr."/".$file);
$date=$date*1000;
$name = basename($dirStr."/".$file);
$size = filesize($dirStr."/".$file);
$type = "file";
if (is_dir($dirStr."/".$file)) $type = "dir";
print($type." ".$date." ".$size." ".$name."<br>\n");
}
closedir($dh);
}
print("</pre>\n");
exit;
}
}
that if that's .. not make it work
Last edited by
javier111 on Sun Jul 04, 2010 5:29 am, edited 1 time in total.
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Sun Jul 04, 2010 5:28 am
apology. but chances are that you send me a version of jdiskexplorer .. php riding in a zip file or similar?
support
Posts: 1503 Joined: Sun Jan 27, 2008 6:19 pm
Post
by support » Sun Jul 04, 2010 9:58 am
Yes x1000 it was I asked. Is it possible to have a chat with you? You can contact support(at)jfileupload(dot)com
javier111
Posts: 9 Joined: Thu Jul 01, 2010 5:28 am
Post
by javier111 » Mon Jul 05, 2010 3:51 am
if i would love .. pot msn want to chat? if so and you add .. and my username is javiergrafica2000(at)hotmail(dot)com, I notice that my English very good noes .. hehe .. but I think we can understand. from already thank you very much for your excellent care and predisposition