Jump to content


Getting info from url


2 replies to this topic

#1 Friiks

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Gender:Male
  • Location:Latvia
  • Interests:Guitar, music, having all sorts of fun...and well enjoying my life (as enjoyable as it can be) as good as I can :D<br /><br />Oh yea, and of course - http://snowmoons.com

Posted 22 November 2006 - 01:53 PM

Hi, you probably have noticed me here as I'm coding my site and keep getting some trouble.
I have a file which reads how many uploads a user has. Then it has to give a link to
another file which allows him to download the file but there's my problem. When I used these files as just files which weren't included into index page (to use ?id=page browsing) they worked fine but now when they are included they don't work at all.

I'll give you the code for them so you can see what I have.
Download.php
//start of php
$getdownloads = mysql_query("SELECT * FROM downloads WHERE `userid` = '".$_SESSION['id']."' ORDER BY id DESC");
while($row = mysql_fetch_assoc($getdownloads))
{
print(" <div id=\"download\">
<a href=\"?i=dlfile&id=$row[id]\">$row[title]</a> - Downloaded $row[count] Times <br>
<img src=\"http://upload.snowmoon.uni.cc/image/$row[id].png\"><br> 
<input size=\"60\" value=\"http://upload.snowmoon.uni.cc/image/$row[id].png\" style=\"font-size: 7pt;\" onclick=\"selectAll(this);\" type=\"text\"></div><br>");
}
//end of php
This gets the file info and puts it in links. When I didn't include them into index page the link was downloadfile.php?&id=fileid but now none of ways I've tried don't work so this was the most right way to do it in my opinion.
downloadfile.php
include "config.php";
$x ="SELECT * from downloads where id='$id'";
$result = mysql_query($x) or die
("Could not execute query : $x." . mysql_error());

while ($row = mysql_fetch_array($result))
{
$id = $row["id"];
$FileURL = $row["url"];
$Count = $row["count"];

header('Location: '.$FileURL);

$x ="update downloads set Count=Count+1 where id='$id'";
$result = mysql_query($x) or die
("Could not execute query : $x." . mysql_error());

}
This gets the file url, increases the download count and gives the file for download.

I think the problem is where it has to get the id from url. But thats what I think.

Any ideas?

Thanks, Matt.

#2 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 22 November 2006 - 04:57 PM

$id = mysql_real_escape_string ( $_GET['id'] );

Put that before you call your query.

#3 Friiks

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Gender:Male
  • Location:Latvia
  • Interests:Guitar, music, having all sorts of fun...and well enjoying my life (as enjoyable as it can be) as good as I can :D<br /><br />Oh yea, and of course - http://snowmoons.com

Posted 23 November 2006 - 08:28 AM

Thanks a lot! ^_^
It works.

But I still have one question - it works if I make it to access the file directly like link is http://myurl.com/dow...file.php?&id=12 but when I tried to access when its included (I use it like this
					  if ($i=="dlfile")
					  {
					  include("downloadfile.php");
					  echo "File download";
					  }
) it gave me this error -

'php error' said:

Warning: Cannot modify header information - headers already sent by (output started at /home/***/public_html/upload/index.php:9) in /home/***/public_html/upload/downloadfile.php on line 15

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/public_html/upload/downloadfile.php on line 8
maybe you know why?

You can test my site on http://upload.snowmoon.uni.cc/ with demo/demo

Edit:

Argh..I just found another error in my image generator. It should generate image of how many times has the file been downloaded but all I get is a broken image. Heres the code of the files that generates it.
<?php 
include("config.php");
$id = mysql_real_escape_string ( $_GET['id'] );
$getdownloads = mysql_query("SELECT * from downloads where id='$id'");
while($row = mysql_fetch_assoc($getdownloads))
{
$image = "signature.png";
$im = @ImageCreateFromPNG($image);
$blue = ImageColorAllocate ($im, 29, 18, 158);
ImageString($im, 3, 45, 15, "$row[title] has been downloaded", $blue); 
ImageString($im, 15, 135, 30, "$row[count]", $blue); 
ImageString($im, 3, 98, 43, "times already", $blue); 
header("Content-Type: image/png");
ImagePNG($im,'',100); 
ImageDestroy ($im); 
}
?>

Edited by Friiks, 23 November 2006 - 12:36 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users