Upload to Dynamic Folders
I use Pure PHP Upload 2.0.0. How can I use the extension to upload files in different folders. The extension is on a side with a product (after insert with id (session)). One field is a catecory field (with a number for the catecory). How can I use this number for the upload folder?
Answer:
DISCLAIMER:
This is extra complimentary content which purpose is to show additional usage that is not part of the product, i.e. it suggests tips for extending the functionality of the product by the users themselves.
It is provided "as is", without warranty of any kind, express or
implied , including but not limited to the warranties of
merchantability, fitness for a particular purpose and nonfringement of
third party rights.
DMXzone does not take responsibility to
support the suggested content to be fully compatible and working as
intended and does not provide support for extended functionality which
is not included in the current release of the extension.
It is highly recommended that only more advanced developers use it.
You can use a dynamic upload folder. For example lets assume that you have a dropdown listbox in your form that allows the users to choose a department. Then you want their files to be saved in "Uploads/<Department>" where <Department> is what they choose.
Then you should just use the following expression as your upload folder:
""Upload/".$_POST['Department']
This assumes that your department dropdown listbox is called "Department".
If you are using PHP version 4.1.0 you need to set long PHP variables as $HTTP_SESSION_VARS and $HTTP_POST_VARS. DMX 2004 uses $_SESSION and $_POST as default.
Comments
How to get this to work
This answer was just too succinct for me. Like many others, I needed more detail!
It took me ages to work out where George's code should go, and then I kept getting errors - but eventually I figured it out after some research. Here's how to get it to work:
How to create a dynamic folder from a dynamic ID:
<input name="ID" type="hidden" id="ID" value="<?php echo $row_customer['ID']; ?>" />
('customer' is my recordset, 'ID' is my field)
In your php page find the line that starts with '$ppu->path ='
$ppu->path = "../uploads/".$_POST['ID'];
../uploads/ is where I keep my uploaded images, but you may have a different name.
.$_POST is how to use the form field to become your folder name.
ID is the name of the hidden field
This error occurs because I'm not using POST to send my ID until my form is submitted (so PHP can't find it until the form is submitted). Nothing to worry about, just suppress the error:
Add this code: <?php error_reporting (E_ALL ^ E_NOTICE); ?>
above the head section in your document.
I placed mine just after the script links, e.g:
<?php require_once('../../../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../../../ScriptLibrary/cGraphicMediator.php'); ?>
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
Hope that helps all the people who have been looking for a detailed answer with examples.
:-)
How to get this to work
You can't read my full previous review, so here's my full answer in the forum:
http://www.dmxzone.com/forum/topic/43692/
You must me logged in to write a comment.