hannnah Posted April 16, 2009 Share Posted April 16, 2009 I've used the upload script shown on this site: http://www.php-mysql-tutorial.com/wikis/php-tutorial/uploading-files-to-the-server-using-php.aspx It works fine, but the download- part is confusing..They say "For listing the download files we just need to copy from the previous script. The real difference start when you click on the download link." So which download link, and where do I put this part of the code? What I want to do, is to list the uploaded images with their information, what would be the best way to do that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/ Share on other sites More sharing options...
laffin Posted April 16, 2009 Share Posted April 16, 2009 I didnt see anything with a download link but its not hard if u take their download script and name it download.php (remember to add the php tags <?php and ?> than create a new script say listings.php <?php include '../library/config.php'; include '../library/opendb.php'; $query = "SELECT id,name, size FROM upload2"; $result = mysql_query($query) or die('Error, query failed'); while($listing=mysql_fetch_array($result)) { ist($id,$name, $size) = $listing; echo "<a href=\"download.php?id={$id}\">{$name}</a>- {$size}<br />\n"; } ?> [/code] however that is oversimplified listing, but it should work. so go ahead and make it pretty Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811252 Share on other sites More sharing options...
hannnah Posted April 16, 2009 Author Share Posted April 16, 2009 I did what u suggested, but I get these errors: Warning: Cannot modify header information - headers already sent by (output started at /mnt/st/c/c6hlehto/public_html/sivusto/download2.php:1) in /mnt/st/c/c6hlehto/public_html/sivusto/download2.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at /mnt/st/c/c6hlehto/public_html/sivusto/download2.php:1) in /mnt/st/c/c6hlehto/public_html/sivusto/download2.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /mnt/st/c/c6hlehto/public_html/sivusto/download2.php:1) in /mnt/st/c/c6hlehto/public_html/sivusto/download2.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811261 Share on other sites More sharing options...
laffin Posted April 16, 2009 Share Posted April 16, 2009 check for spaces before <?php tags or any spaces after ?> tag spaces at these two points can cause that error the code I posted I spotted a type change ist($id,$name, $size) = $listing; to: list($id,$name, $size) = $listing; Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811269 Share on other sites More sharing options...
hannnah Posted April 16, 2009 Author Share Posted April 16, 2009 yes I noticed the type, just a small one...I don't see any whitespaces(I'm using notepad), except at the end of the file there's some space but can't get rid of it? Also, I don't need a link to the picture, but to show the picture there, where now there's a link to it... Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811294 Share on other sites More sharing options...
laffin Posted April 16, 2009 Share Posted April 16, 2009 file: download.php <?php if(isset($_GET['id'])) { include '../library/config.php'; include '../library/opendb.php'; $id = $_GET['id']; $query = "SELECT name, type, size, path FROM upload2 WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $filePath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); readfile($filePath); include '../library/closedb.php'; exit; } ?> if yer using notepad and a linux server that could be the problem. windows uses a line terminator of CR + LF while linux uses only LF it shud look like this. header lines shud be on 12-14 not 14-16 to display images u need to change $query = "SELECT id,name, size FROM upload2"; to $query = "SELECT id,name, size,path FROM upload2"; and list($id,$name, $size) = $listing; echo "<a href=\"download.php?id={$id}\">{$name}</a>- {$size}<br />\n"; to list($id,$name, $size, $imagepath) = $listing; echo "<img src=\"$imagepath\"><br />\n"; that should do it Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811313 Share on other sites More sharing options...
hannnah Posted April 16, 2009 Author Share Posted April 16, 2009 Ok, that's it, I'm using our schools server which is linux...what should I use instead of notepad? I can't access the server and test it right now, but I'll keep testing, cos it should work especially with your tips, so thank so much for the help!!! Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811771 Share on other sites More sharing options...
laffin Posted April 16, 2009 Share Posted April 16, 2009 I use a portable php environment for testing. QuickPHP (Small development server) PHP 5.2.29 (Stripped down for bare essentials) Dev-PHP2 (PHP Development IDE) These are portable and run under windows. At home, I use UltraEdit (Commercial) Zend Studio (Commercial) But if yer looking for a small portable editor. npp++ (Notepad Plus Plus, is a good replacement) There are plenty of other editors, but if yer just getting started, I wud suggest one that is meant to work with PHP, as this will give u some unique benefits for php programming. Quote Link to comment https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/#findComment-811824 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.