Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/154307-uploading-files-to-the-server-using-php/
Share on other sites

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

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

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...

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

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!!!

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.