////upload.php source
//FORCE SOME PHP_INI SETTINGS
ini_set( "max_execution_time", 120 );
ini_set( "max_input_time", 240 );
ini_set( "upload_max_filesize", "50M" ); //Maximum allowed size for uploaded files.
ini_set( "post_max_size", "60M" ); //Maximum size of POST data that PHP will accept.
ini_set( "memory_limit", "70M" ); //Maximum amount of memory a script may consume
This works by pulling the "relpathinfo" $_POST information for each file, and prepending it to the filename sent through the $_FILES array. Note that you need to have the nbFilesPerRequest set to 1 in the applet page, or else you'll end up with files all over the place, as I've not made the relpathinfo variable 'dynamic'. This is a quick and dirty fix, and I hope to get it working with the file chunks, but so far no luck with that.
Any help or comments would be greatly appreciated!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
////upload.php code
//FORCE SOME PHP_INI SETTINGS
ini_set( "max_execution_time", 120 );
ini_set( "max_input_time", 240 );
//ini_set( "upload_max_filesize", "50M" ); //Maximum allowed size for uploaded files.
//ini_set( "post_max_size", "60M" ); //Maximum size of POST data that PHP will accept.
//ini_set( "memory_limit", "70M" ); //Maximum amount of memory a script may consume
Hi,
I'm sorry but it's not working to me - JUpload is simply not sending "relpathinfo" in the POST request (even if I got nbFilesPerRequest=1). What version are you using? I got 3.0.1.
I was having alot of problems with it at first, until I deleted the "temporary files" in the Java control panel. Even though my site was referencing the proper version of the uploader, Java had cached another version, and would pull that up instead.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
can you please send me "compiled" version of it? I'm not Java developer and if I don't have to learn, how to compile Java on MacOS, I'd be very happy :-) My email is: libor.vanek [at] gmail.com
Thx,
Libor
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The compiled version of the applet is available in each package available on sourceforge. Open the release jar file, and the /wwwroot/wjhk.jupload.jar file. It's the compiled applet.
You can also browse SVN, and get the up to date applet (same path).
Etienne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
I'm fairly new to PHP, so there may, in fact, be a much better way of doing this, but it works for me rather well.
////file_upload.php source
<html>
<head>
<title>Uploader</title>
</head>
<body>
<applet name="JUpload" code="wjhk.jupload2.JUploadApplet" archive="wjhk.jupload.jar" width="700" height="500" mayscript>
<!--param name="maxChunkSize" value="500000">
<param name="uploadpolicy" value="PictureUploadPolicy"-->
<param name="lookandfeel" value="system">
<param name="nbFilesPerRequest" value="1">
<param name="postURL" value="upload.php">
Java 1.5 or higher plugin required.
</applet>
</body>
</html>
////upload.php source
//FORCE SOME PHP_INI SETTINGS
ini_set( "max_execution_time", 120 );
ini_set( "max_input_time", 240 );
ini_set( "upload_max_filesize", "50M" ); //Maximum allowed size for uploaded files.
ini_set( "post_max_size", "60M" ); //Maximum size of POST data that PHP will accept.
ini_set( "memory_limit", "70M" ); //Maximum amount of memory a script may consume
$save_path="files/";
array_walk($_FILES, 'moveFiles');
print_r($_FILES);
print_r($_POST);
//-----------------------------------------------------------------------------
// FUNCTIONS
//-----------------------------------------------------------------------------
function moveFiles($name, $key) {
global $save_path;
$id = $FILES[$key];
$tmpname = $_FILES[$key]['tmp_name'];
$filename = stripslashes($_FILES[$key]['name']);
$error = $_FILES[$key]['error'];
if ($error == UPLOAD_ERR_OK) {
$relpath = str_replace("\", "/", stripslashes($_POST["relpathinfo"][0]));
$filename = $relpath . "/" . $filename;
$filename = str_replace(" ", "", $filename);
echo $filename."\n";
$pos = strrpos($filename, "/");
if ($pos === false) {
$file = $filename;
$path = $save_path;
} else {
$file = substr($filename, $pos);
$dir = substr($filename, 0, $pos);
$path = $save_path . "/" . $dir;
}
}
// Creates the directories if needed.
function mkdir_recursive($dir){
do {
$tempdir = $dir;
while (!is_dir($tempdir)) {
$basedir = dirname($tempdir);
} while ($tempdir != $dir);
}
This works by pulling the "relpathinfo" $_POST information for each file, and prepending it to the filename sent through the $_FILES array. Note that you need to have the nbFilesPerRequest set to 1 in the applet page, or else you'll end up with files all over the place, as I've not made the relpathinfo variable 'dynamic'. This is a quick and dirty fix, and I hope to get it working with the file chunks, but so far no luck with that.
Any help or comments would be greatly appreciated!
Now working with chunked files!
////file_upload.php code
<html>
<head>
<title>Uploader</title>
</head>
<body>
<applet name="JUpload" code="wjhk.jupload2.JUploadApplet" archive="wjhk.jupload.jar" width="700" height="500" mayscript>
<param name="maxChunkSize" value="500000">
<param name="lookandfeel" value="system">
<param name="nbFilesPerRequest" value="1">
<param name="postURL" value="upload.php">
Java 1.5 or higher plugin required.
</applet>
</body>
</html>
////upload.php code
//FORCE SOME PHP_INI SETTINGS
ini_set( "max_execution_time", 120 );
ini_set( "max_input_time", 240 );
//ini_set( "upload_max_filesize", "50M" ); //Maximum allowed size for uploaded files.
//ini_set( "post_max_size", "60M" ); //Maximum size of POST data that PHP will accept.
//ini_set( "memory_limit", "70M" ); //Maximum amount of memory a script may consume
$save_path="files/";
array_walk($_FILES, 'moveFiles');
//print_r($_FILES);
//print_r($_POST);
//-----------------------------------------------------------------------------
// FUNCTIONS
//-----------------------------------------------------------------------------
function moveFiles($name, $key) {
global $save_path;
$id = $FILES[$key];
$tmpname = $_FILES[$key]['tmp_name'];
$filename = stripslashes($_FILES[$key]['name']);
$error = $_FILES[$key]['error'];
$size = $_FILES[$key]['size'];
if ($error == UPLOAD_ERR_OK) {
$relpath = str_replace("\", "/", stripslashes($_POST["relpathinfo"][0]));
$filename = $relpath . "/" . $filename;
//REMOVE SPACES FROM FILE & FOLDER NAMES, REPLACED WITH ''
$filename = str_replace(" ", "_", $filename);
echo $filename."\n";
$pos = strrpos($filename, "/");
if ($pos === false) {
$file = $filename;
$path = $save_path;
} else {
$file = substr($filename, $pos);
$dir = substr($filename, 0, $pos);
$path = $save_path . "/" . $dir;
}
//CREATE SUB-DIR IF NEEDED
if (!file_exists($path)) { mkdir_recursive($path); }
//CHECK FOR MULTI-PART FILE;
if (isset($_POST["jupart"])) {
//READ TEMP FILE DATA
$tmpFileHandle = fopen($tmpname, 'r');
$dataInsert = fread($tmpFileHandle, $size);
fclose($tmpFileHandle);
}
// Creates the directories if needed.
function mkdir_recursive($dir){
do {
$tempdir = $dir;
while (!is_dir($tempdir)) {
$basedir = dirname($tempdir);
} while ($tempdir != $dir);
}
sorry all, I had a path typo; here's the fixed file.
////upload.php code
//FORCE SOME PHP_INI SETTINGS
ini_set( "max_execution_time", 120 );
ini_set( "max_input_time", 240 );
$save_path="files/";
if (!file_exists($save_path)) { mkdir_recursive($save_path); }
array_walk($_FILES, 'moveFiles');
//-----------------------------------------------------------------------------
// FUNCTIONS
//-----------------------------------------------------------------------------
function moveFiles($name, $key) {
global $save_path;
$id = $FILES[$key];
$tmpname = $_FILES[$key]['tmp_name'];
$filename = stripslashes($_FILES[$key]['name']);
$error = $_FILES[$key]['error'];
$size = $_FILES[$key]['size'];
if ($error == UPLOAD_ERR_OK) {
$relpath = str_replace("\", "/", stripslashes($_POST["relpathinfo"][0]));
$filename = $relpath . "/" . $filename;
//REMOVE SPACES FROM FILE & FOLDER NAMES, REPLACED WITH ''
$filename = str_replace(" ", "_", $filename);
echo $filename."\n";
$pos = strrpos($filename, "/");
if ($pos === false) {
$file = $filename;
$path = $save_path;
} else {
$file = substr($filename, $pos);
$dir = substr($filename, 0, $pos);
$path = $save_path . $dir;
}
//CREATE SUB-DIR IF NEEDED
if (!file_exists($path)) { mkdir_recursive($path); }
//CHECK FOR MULTI-PART FILE;
if (isset($_POST["jupart"])) {
//READ TEMP FILE DATA
$tmpFileHandle = fopen($tmpname, 'r');
$dataInsert = fread($tmpFileHandle, $size);
fclose($tmpFileHandle);
}
// Creates the directories if needed.
function mkdir_recursive($dir){
do {
$tempdir = $dir;
while (!is_dir($tempdir)) {
$basedir = dirname($tempdir);
} while ($tempdir != $dir);
}
Great!
Thanks for your contribution.
We'll try to embed it in the package, or at least add a link to this thread in the doc of the next release.
(added on my todo list)
Etienne
Hi,
I'm sorry but it's not working to me - JUpload is simply not sending "relpathinfo" in the POST request (even if I got nbFilesPerRequest=1). What version are you using? I got 3.0.1.
My "debug output" of send parameters by JUpload
_FILES: File0 => Array
name => yellow.gif
type => image/gif
tmp_name => /tmp/phpfe3iGG
error => 0
size => 1096
_POST: mimetype => image/gif
_POST: md5sum => 2caaa7e071620c5b686d8550335612e2
I also "grepped" the JUpload source files (3.0.1) for the "relpath" string and no match :-(
Thanks for any help,
Libor
I'm using 3.1.0b1 [SVN-Rev: 309]
I was having alot of problems with it at first, until I deleted the "temporary files" in the Java control panel. Even though my site was referencing the proper version of the uploader, Java had cached another version, and would pull that up instead.
Hi,
can you please send me "compiled" version of it? I'm not Java developer and if I don't have to learn, how to compile Java on MacOS, I'd be very happy :-) My email is: libor.vanek [at] gmail.com
Thx,
Libor
Hi,
The compiled version of the applet is available in each package available on sourceforge. Open the release jar file, and the /wwwroot/wjhk.jupload.jar file. It's the compiled applet.
You can also browse SVN, and get the up to date applet (same path).
Etienne
Ah, I didn't notice. Thx.