Pure PHP Upload 2 Support Product Page

This topic was archived

How to include PHP recordID in folder or file names

Asked 26 Jun 2009 19:05:43
1
has this question
26 Jun 2009 19:05:43 Kay Kentfield posted:
AIM
To use one or more PHP record ID's to create folder or file names, e.g:
  • Photo1_CLIENTID or photo2_CLIENTID (client's photo 1, clients's photo 2 etc)
  • CLIENTID_photo_NEWSID (client's so I can pull up the right photo for the right client's news article)

PROBLEM
  1. As you suggest, I can dynamically create a folder and upload by putting the recordID into a cookie, and using "$ppu->path = "../images/".$_COOKIE['ID']; " ... BUT some clients have cookies disabled.
  2. Link clients multiple photos with ID's in other tables with multiple records (latest guests, latest news) where I need to link specific records with photos.
  3. Good practice. When clients are deleted unless I can use record ID's for folders/filenames I won't be able to find them easily to delete them.
    Good management: keeping all clients photos together in one folder (created using their record ID)


  4. Lots of customers have asked you about this in the support forum and not had an answer - so I know this will help a lot of people (even if the answers is that it can't be done yet!).
    Many thanks for your help
    Edited by - Kay Key on 26 Jun 2009  19:06:53

    Edited by - Kay Key on 26 Jun 2009  19:07:29

Replies

Replied 05 Aug 2009 22:53:55
05 Aug 2009 22:53:55 Kay Kentfield replied:
George has answered this: www.dmxzone.com/go?4545
BUT his 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:

1. In your upload form, add a hidden text field which has your dynamic ID field from your recordset. E.g:
<input name="ID" type="hidden" id="ID" value="<?php echo $row_customer['ID']; ?>" />
('customer' is my recordset, 'ID' is my field)


2. In your code, edit the folder destination (where you want your files uploaded to)
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


3. If you get an 'invalid index' error, suppress it:
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); ?>

I'm thrilled to bits with PHP Upload 2 now I can do this.

Hope that helps all the people who have been looking for a detailed answer with examples.
[]
Replied 06 Aug 2009 01:04:49
06 Aug 2009 01:04:49 Patrick Julicher replied:
Hi Kay,

Nice and easy explanation you made. For the ASP version there is already an FAQ (www.dmxzone.com/go?16784) that handles the upload to a variable folder. With a little imagination one could easily convert this into a dynamic folder being created from a specific ID. I will make sure that an FAQ will be available for uploading to dynamic folders using ID's or even Usernames.

Kind regards, Patrick

Reply to this topic