Page 1 of 1

help with file upload please

Posted: Thu May 15, 2008 2:23 am
by zipadee
Hi all,

On the website I'm creating, there's going to be a page with articles on. Basically what I want to do is allow my client to upload articles himself on a regular basis.

My PHP knowledge is very limited. However, using online tutorials etc. I've managed to create a user login. I've also created a form for uploading files to the server. This all (apparently) works fine.

I'm stuck now tho :(

How do I get the uploaded articles from the server back down into the actual articles page?

Ideally, I would like the articles' name and author (from the form) to be stored in a database. But I'm not sure if it's feasible to have the actual file that's being uploaded stored in the database too - I think the space I have is quite limited.

Thanks.

Re: help with file upload please

Posted: Thu May 15, 2008 3:50 am
by aceconcepts
What you could do is store all the author details and then store the file name of the uploaded file in an "articles" table.

e.g.

tblAuthor (intAuthorId, strAuthorname...)

tblArticles (intArticleId, strArticleTitle, strArticleFileName)

tblAuthorArticles (intAuthorId, intArticleId)

strArticleFileName will be the actual name of the file you initially upload.

So, when you come to retrieving the authors and their articles you would query the three tables above like:

Code: Select all

 
$sql="SELECT * FROM tblAuthor
        INNER JOIN tblAuthorArticles ON tblAuthor.intAuthorId=tblAuthorArticles.intAuthorId
        INNER JOIN tblArticles ON tblAuthorArticles.intArticleId=tblArticles.intArticleId";
 
The INNER JOIN basically means you will be getting data from all three tables providing there are "related" IDs in tblAuthorArticles.

When you output the article file you will obvioulsy need to reference the path to where the file is located

e.g.

Code: Select all

 
$filePath="uploads/articles/";
$article=$databaseRow['strArticleFileName']; //e.g. "Learning PHP.html"
 
echo $filePath . $article;
 
//This will output: "uploads/articles/Learning PHP.html"
 
Hope it makes sense.