This topic is locked

Multi Image/File Upload?

1/24/2010 12:23:55 AM
PHPRunner General questions
T
th3fallen author

Is it at all possible to be able to upload more than one image/file per row, linked by the id of the description of the file and also have the location of the files listed in a seperate database?
I'm really intrested in just the multi upload but if the rest someone knows how to do your help will be most appreciated.

ficcionista 1/26/2010

Hi,
so far all i've come up with is creating multiple "file" fields, but this option is very limited.
What i need is for a user to be able to upload multiple files associated to one record. However the number of files uploaded may vary for each record.
For example:
Record one - Client needs to upload three files.

Record two - Client needs to upload one file.

Record three - Client needs to upload 5 files.

...

etc.
Another thing. In my case, the uploaded files won't be stored in the database, but in a common folder for all uploads.
Anybody has any ideas?

J
Jane 1/26/2010

Hi,
you can create separate table for uploaded files and set up master-detail relationships between main table and table with files on the Datasource tables tab.

ficcionista 1/26/2010

I guess that this is going to be a newbie question, but anyway here it goes.
First: I will be storing the uploaded files in a folder, storing a link to the file in the DB.
I have two tables.
A Master table wich the users will List, Add, Edit and View.
An Upload table wich will store a link to every file uploaded.
I'm linking the master table's primary KEY to a field with the same name in the upload table. That way every file uploaded will be associated to that KEY
So the question is:
How do I add a field to the Master table's ADD and EDIT pages? That field will be saving the record of the upload on the second table.

T
th3fallen author 1/26/2010

I'm glad someone else is trying to do the same thing im attempting, it would be really nice to have it added to 5.2 wink wink....

J
Jane 1/27/2010

ficc,
I'm not that I understand your question.

Could you clarify what relationship you've set up between these fields and how you've added new files?

ficcionista 1/27/2010



ficc,
I'm not that I understand your question.

Could you clarify what relationship you've set up between these fields and how you've added new files?



Yes, i'll try to clarify.
What i need is:
When a user enters the ADD/EDIT pages of a certain record there will be an upload field, enabling the user to attach files to that record.

When a user enters the VIEW page , he will see a list of all files that are related to that record.
So far my tables are set up like this:

Main Table - netw

CREATE TABLE IF NOT EXISTS `netw` (

`netwID` int(11) NOT NULL AUTO_INCREMENT,

`siteCODE` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,

`siteNAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,

(...)

`update_by` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,

PRIMARY KEY (`netwID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1092 ;


Uploads Table - uploads

CREATE TABLE IF NOT EXISTS `uploads` (

`fileID` int(11) NOT NULL AUTO_INCREMENT,

`netwID` int(11) NOT NULL, `siteCODE` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`siteNAME` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`filename` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`file_desc` text COLLATE utf8_unicode_ci NOT NULL,

`upload_by` varchar(255) COLLATE utf8_unicode_ci NOT NULL,

`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

PRIMARY KEY (`fileID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabela para Uploads de Ficheiros' AUTO_INCREMENT=7 ;


I have relations created in the following fields:
netwID --> netwID

siteCODE -->siteCODE --> Drop-down box.

siteNAME -->siteNAME --> Drop-down box dependant on the above.

J
Jane 1/27/2010

Hi,
to add files to the detail table use ADD page of the detail table, not ADD page of the master table.

First add new master record, the click on the link to the detail table on the master list page and add files to the detail table.

ficcionista 1/28/2010

Hi, I've come up with a solution for what i need (sort of).
I've eliminated the netwID field on the uploads table and now the relations are only these:
Master(netw) --> Details(uploads)

siteCODE -->siteCODE --> Drop-down box.

siteNAME -->siteNAME --> Drop-down box dependant on the above.
I've set up PHPR to generate pages for both tables. When a user needs to upload a file, he'll have to access the uploads_add.php, and chose the siteCODE and siteNAME. That way, that file will be associated to a specific site.
Then,

I've created a snippet on the netw_view.php page in order to view the files associated to that record. I've done in three steps.

  1. Added some php code on the visual editor tab, doesn't need to be code, just something to make PHPR add the snippet to the events tab.
  2. On the event tab load the siteCODE into a Session Variable:

function BeforeShowView($xt,$templatefile,$values)

{

$_SESSION["code"] = $values["siteCODE"];

} // function BeforeShowView


3. On the events tab edit the Snippet:

global $conn;

$code = $_SESSION["code"]; //Transforming the session variable into something usable in MySQL.

//This will validate if this site has any files associated to it.

$strSQLExists = "select * from uploads where siteCODE='$code'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

//This will echo the result.

if($data)

{//If we find results, then output them, with the respective download link.

$strSQLx = "select * from uploads where siteCODE='$code' order by filename asc";

$query = db_query($strSQLx,$conn);

while($row = db_fetch_array($query))

echo "<a href=\"uploads_download.php?field=filename&key1=" .$row["fileID"]. "\">" .$row["filename"]. "</a><br />";

}

else

{//If there are no results, present some text.

echo "Não há ficheiros anexados a este registo";

}

;


I don't yet know if we can use Sessions Variables in MySQL queries (Everytime I tried i got invalid SQL Syntax) so I decided to play a little with the Session Variables and PHP Variables.
I hope that is helpful