dynamic upload directory

Upload core product.
Post Reply
frankups1
Posts: 8
Joined: Tue Sep 22, 2009 9:38 pm

dynamic upload directory

Post by frankups1 »

i am trying to allow users to make their own galleries and upload the images to that gallery.
the first page of the gallery setup the user enters the name of their gallery, and then creates a folder on the server for that gallery in that users folder. is is possible to pass that directory name to the process.php script as a variable?
the new gallery form:

Code: Select all

<form action="make_folder.php" method="post">
User: <input name="gallery" type="text" />
<input type="submit" value="Create Gallery"/>

Code: Select all

$user=$_SESSION['myemail'];
$gallery = $_POST["gallery"];
$user = preg_replace("/[^a-zA-Z0-9\s]/", "", $user);
$upload_dir = "/var/www/own_site_dev/galleries/".$user."/".$gallery;
if (!is_dir("/var/www/own_site_dev/galleries/".$user)){
	mkdir("/var/www/own_site_dev/galleries/".$user, 0777);
	mkdir("/var/www/own_site_dev/galleries/".$user."/".$gallery, 0777);
}
else {
	mkdir("/var/www/own_site_dev/galleries/".$user."/".$gallery, 0777);
}

if (is_dir("/var/www/own_site_dev/galleries/".$user."/".$gallery)){
	echo $gallery." has been created successfully created";
	}
after this code is where the jfileupload applet resides:

Code: Select all

<?php require('../own_site_dev/applet_http_ipreview.js')?>
i tried changing applet_http_ipreview.js to applet_http_ipreviewjs.php and putting

Code: Select all

process.php?gallery=<? echo $gallery; ?>&user=<? echo $user;?>
but it only seems to work for the forward url. am i going about this the right way?

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: dynamic upload directory

Post by support »

ACCOUNT extra parameter is designed for this usage. For instance,
<PARAM NAME="param8" VALUE="account">
<PARAM NAME="value8" VALUE="users/user1">

Then you can get the 'account' value with $_POST['account'] in each upload request. You have a sample in our free PHP sample script: http://www.jfileupload.com/products/tools/index.html
This parameter can also be forwarded in the redirect URL after upload.

Does it help ?

Notice that you can pass any custom parameter with extra parameter. For instance:
<PARAM NAME="param9" VALUE="firstname">
<PARAM NAME="value9" VALUE="John">
$firstname = $_POST['firstname']

frankups1
Posts: 8
Joined: Tue Sep 22, 2009 9:38 pm

Re: dynamic upload directory

Post by frankups1 »

thank you for your quick response, but i need the value of lets say "firstname" to be different for every user. so instead of:

<PARAM NAME="param9" VALUE="firstname">
<PARAM NAME="value9" VALUE="John">
$firstname = $_POST['firstname']

i need something like:

<PARAM NAME="param9" VALUE="firstname">
<PARAM NAME="value9" VALUE="$firstname">
$firstname = $_POST['firstname']

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: dynamic upload directory

Post by support »

Yes, it will work if you include the applet in a PHP page:

<PARAM NAME="param9" VALUE="firstname">
<PARAM NAME="value9" VALUE="<?php echo $firstname ?>">

frankups1
Posts: 8
Joined: Tue Sep 22, 2009 9:38 pm

Re: dynamic upload directory

Post by frankups1 »

i have tried what you recommended and still nothing. this is my code, maybe im overlooking some small detail:
this is the page where the applet lives:

<?php session_start(); ?>

<?php require('../own_site_dev/_includes/db_info.php')?>
<?php require('../own_site_dev/_includes/db_connect.php')?>

<?php require('../own_site_dev/_includes/head.php')?>
<!-- BODY -->

<!-- WRAP -->
<div id="wrap">
<?php require('../own_site_dev/_includes/header.php')?>
<?php require('../own_site_dev/_includes/nav.php')?>
<div id="content">
<?php require('../own_site_dev/_includes/left_col.php')?>
<div id="main_content">

<?php
$user=$_SESSION['myemail'];
$gallery = $_POST["gallery"];
$user = preg_replace("/[^a-zA-Z0-9\s]/", "", $user);
$upload_directory = "/var/www/own_site_dev/galleries/".$user."/".$gallery;
if (!is_dir("/var/www/own_site_dev/galleries/".$user)){
mkdir("/var/www/own_site_dev/galleries/".$user, 0777);
mkdir("/var/www/own_site_dev/galleries/".$user."/".$gallery, 0777);
}
else {
mkdir("/var/www/own_site_dev/galleries/".$user."/".$gallery, 0777);
}

if (is_dir("/var/www/own_site_dev/galleries/".$user."/".$gallery)){
echo $gallery." has been created successfully created";
}


?>
<div>

<script type="text/javascript">

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="475" HEIGHT="475" NAME="fileupload" codebase="http://java.sun.com/update/1.4.2/jinsta ... on=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/previewui.jar,lib/ifilter.jar" ');
document.write('NAME="fileupload" ');
document.write('WIDTH="640" ');
document.write('HEIGHT="350" ');
document.write('url="http://mine.com/own_site_dev/process.php" ');
document.write('paramfile="uploadfile" ');
document.write('param1="todo" ');
document.write('value1="upload" ');
document.write('transferui="jfileupload.transfer.client.preview.PreviewerTransferUI" ');
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/ind ... "><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/previewui.jar" WIDTH="475" HEIGHT="475" 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/previewui.jar,lib/ifilter.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://mine.com/own_site_dev/process.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="transferui" VALUE="jfileupload.transfer.client.preview.PreviewerTransferUI">');
document.writeln('<PARAM NAME="resources" VALUE="i18n_bar">');
document.writeln('<PARAM NAME="transferuiresources" VALUE="i18n_pane">');
document.writeln('<PARAM NAME="mode" VALUE="http">');
document.writeln('<PARAM NAME="filter" VALUE="jfileupload.upload.client.filter.ImageFilter">');
document.writeln('<PARAM NAME="filterproperties" VALUE="scaling.properties">');
document.writeln('<PARAM NAME="forward" VALUE="http://mine.com/own_site_dev/">');
document.writeln('<PARAM NAME="post" VALUE="http://mine.com/own_site_dev/multi_test.php">');
document.writeln('<PARAM NAME="postparameters" VALUE="extra">');
document.writeln('<PARAM NAME="param8" VALUE="upload_directory">');
document.writeln('<PARAM NAME="value8" VALUE="<?php echo $upload_directory; ?>">');

// END
if (_ie == true) {
document.writeln('</OBJECT>');
}
else if (_ns == true && _ns6 == false) {
document.writeln('</NOEMBED></EMBED>');
}
else {
document.writeln('</APPLET>');
}
//-->
</script>

</div>


<?php require('../own_site_dev/_includes/right_col.php')?>
<?php require('../own_site_dev/_includes/footer.php')?>
</div>

and this is the first couple lines of process.php, i havent changed anything else other than the first couple lines:

<?php

$upload_dir=$_POST['upload_directory'];

$max_size = 1500000000;
$createsubfolders = "true";
$keepalive = "false";
$resume = "false";
...

am i missing something?

thank you again for oyur quick response

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: dynamic upload directory

Post by support »

Your code seems fine. What do you see when you click "View Source" on generated PHP page?
Do you have any Javascript error message? A JavaScript issue may prevent the parameter to be passed.
Finally are you testing it under Internet Explorer or Firefox?

frankups1
Posts: 8
Joined: Tue Sep 22, 2009 9:38 pm

Re: dynamic upload directory

Post by frankups1 »

i made a test page to see if the applet is sending any variables to anywhere so i forwarded and posted to that page:

document.writeln('<PARAM NAME="forward" VALUE="http://mine.com/own_site_dev/testjsparams.php">');
document.writeln('<PARAM NAME="post" VALUE="http://mine.com/own_site_dev/testjsparams.php">');
document.writeln('<PARAM NAME="postparameters" VALUE="extra">');
document.writeln('<PARAM NAME="param8" VALUE="upload_directory">');
document.writeln('<PARAM NAME="value8" VALUE="<?php echo $upload_directory; ?>">');


and then on the test page i have the following code:
<?php
$filename1uploaded = $_POST['filename1'];
$filename2uploaded = $_POST['filename2'];
$upload_directory = $_POST['upload_directory'];
echo $filename1uploaded;
echo $filename2uploaded;
echo $upload_directory;
?>

the test page http://mine.com/own_site_dev/testjsparams.php comes up after the upload but it is completely blank. i do not get any javascript errors and it says that the files have been uploaded. if there are 1 image or 30 images it goes though all of them like they are actually being uploaded. i have tested this on firefox as well as safari. i guess i should also state that when i first downloaded the code $upload_dir= /var/www/myuploadfolder in the process.php the images uploaded fine.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: dynamic upload directory

Post by support »

And what about:
$filename1uploaded = $_GET['filename1'];

"forward" parameter generates a GET request only.

frankups1
Posts: 8
Joined: Tue Sep 22, 2009 9:38 pm

Re: dynamic upload directory

Post by frankups1 »

that didnt work either... i think im gonna start over and see where that gets me, i have to be overlooking something

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: dynamic upload directory

Post by support »

You have a sample PHP script to read parameters in add-ons section:
http://www.jfileupload.com/products/tools/index.html

Post Reply