Jump to content

File Uploading


ChompGator

Recommended Posts

I have a script that uploads a file to my server...But this is my issue, I dont know if I should upload the file to a MySQL db, or just a file folder on my server...Because later on in the website - people will be able to view these uploaded files (the uploaded files are monthly "News-letters") and I want them displayed on a page like this

<2008-04 Newsletter>

<2008-02 Newsletter>

<2008-03 Newsletter>

 

So my question is what is the recommendations from some of you who have done this before, better to use a MySQL db, then just echo the information from the db when I want it, or would simply just uploading it into a folder and calling on it when needed work ok?

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/
Share on other sites

as far as I'm aware, both should work ok but I'd personally recommend to putting it on your file server. If you are going to use a php script to display the images on "news-letters" I'd recommend echoing the image name to the DB at the same time. You will have to make sure the images are named unique as your script to upload them will overwrite the old one without any warning.

 

Hope this helps

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/#findComment-619180
Share on other sites

I sorted out my script it works now...

 

However this is what I want it to do now - say you want to download a Newsletter

I want it to list the newsletters by $filename but also have a link on it so when you see <2008-09> you can click the <2008-09> and it links directly to the file.

(I cant seem to get my script working its just showing a blank page) - when the files are uploaded they're assigned a unique ID in the database

 

Any advice?

<?php
// Connects to your Database 
mysql_connect("**", "***", "***") or die(mysql_error()); 
mysql_select_db("legion") or die(mysql_error()); 

$query = "SELECT id, name FROM uploads";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
} 
else
{
while(list($id, $filename) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php=$id;?>"><?php=$filename;?></a> <br>
<?php close();
?>

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/#findComment-619259
Share on other sites

Is the link displaying correctly?

If it is, I noticed your second loop is not closed (you put { instead of })

 

If it's not, try leaving the php tag open all the way and inserting;

<?php
// Connects to your Database 
mysql_connect("**", "***", "***") or die(mysql_error()); 
mysql_select_db("legion") or die(mysql_error()); 

$query = ("SELECT id, name FROM uploads")
or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
} 
else
{
while($info = mysql_fetch_array($result))
}
{
print '<a href="download.php?id=';
print $info['id'];
print '">';
print $info['filename'];
print '</a> <br />';
}
?>

 

That's what I have on my code that does pretty much the same thing, and it seems works fine.

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/#findComment-619279
Share on other sites

hmm, nope not working at all...

Can I show you a URL?

http://www.kensingtonlegion.com/login/admin/newtest.php

That is where I have this php script that is supposed to show whats in the db table...

 

But its just a blank page :(...

 

Ill try out some more tests, but Im open to trying anything at this point

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/#findComment-619306
Share on other sites

Yep, its just blank, the script is as follows (right now, just trying to get it to list whats in the database with a link on it to the document as discussed aboved, so the only script on the page is:

 

<?php
// Connects to your Database 
mysql_connect("**", "***", "***") or die(mysql_error()); 
mysql_select_db("legion") or die(mysql_error()); 

$query = ("SELECT id, name FROM uploads")
or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
} 
else
{
while($info = mysql_fetch_array($result))
}
{
print '<a href="download.php?id=';
print $info['id'];
print '">';
print $info['filename'];
print '</a> <br />';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/120185-file-uploading/#findComment-619496
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.