[SOLVED] PHP Scripting Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vientorio
Forum Newbie
Posts: 11
Joined: Thu Dec 11, 2003 2:37 am
Location: New Zealand

[SOLVED] PHP Scripting Problems

Post by vientorio »

We are mirroring a download site from here in New Zealand. The download setup is PHP. We installed PHP 4.3.4 on IIS 5 (2k server).

When we click this url
http://bgw.gtcs.net.nz/dl.php?file=Airbornev1.5.ZIP

we get an error on line 60 of dl.php

I am a newbie to PHP, you can look at the dl.php file and the ftp://mirrors.gtcs.net.nz

it uses the server.txt file to create the download link url so the clients browser will be pointed to the correct file
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you do us a favour and post lines 50 - 65 of dl.php.

Mac
vientorio
Forum Newbie
Posts: 11
Joined: Thu Dec 11, 2003 2:37 am
Location: New Zealand

Post by vientorio »

I think this is it in dl.asp

$display_template = "<div align=\"center\">
<center>
<table border=\"0\" width=\"25%\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td width=\"100%\"><p align=\"center\"><font face=\"Tahoma\" size=\"2\" color=\"#000080\"><b><a href='<URL>'target=\"_blank\"</b></font><font face=\"Tahoma\" size=\"2\"><b><MIRROR></a></b></font></td>
</tr>
<tr>
<td width=\"100%\">
<p align=\"center\"><font face=\"Tahoma\" size=\"2\" color=\"#000000\">(Opens In
A New Window)</font></td>
</tr>
</table>
</center>
</div>";

$servers = file ('servers.txt');
for ($i = 0; $i < count ($servers); $i++)

Hope this helps.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

which of those lines in actually line 60?

Mark
vientorio
Forum Newbie
Posts: 11
Joined: Thu Dec 11, 2003 2:37 am
Location: New Zealand

Post by vientorio »

Here is the code on line 60:

Code: Select all

<?php
  $sarr[2] = str_replace ('<FILENAME>', $file, $sarr[2]);
?>
This is the code leading up to it

Code: Select all

<?php
$display_template = "<div align="center">
  <center>
  <table border="0" width="25%" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100%"><p align="center"><font face="Tahoma" size="2" color="#000080"><b><a href='<URL>'target="_blank"</b></font><font face="Tahoma" size="2"><b><MIRROR></a></b></font></td>
    </tr>
    <tr>
      <td width="100%">
        <p align="center"><font face="Tahoma" size="2" color="#000000">(Opens In
        A New Window)</font></td>
    </tr>
  </table>
  </center>
</div>";

$servers = file ('servers.txt');
for ($i = 0; $i < count ($servers); $i++)

{
  $sarr = explode ('::', $servers[$i]);
  $sarr[2] = str_replace ('<FILENAME>', $file, $sarr[2]);
  $dtmp = str_replace ('<URL>', $sarr[2], $display_template);
  $dtmp = str_replace ('<MIRROR>', $sarr[1], $dtmp);
  $dtmp = str_replace ('<LOCATION>', $sarr[0], $dtmp);
  $dtmp = str_replace ('<COUNTER>', $i + 1, $dtmp);
  echo $dtmp;
}
?>
Many thanks for looking at this for me. Apologies for posting twice, was unsure of the first place to post.

Kind Regards,

Geoff.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Well do you actually have the variable $file defined somewhere in the script? If not, this is your problem.
PhP T@mer
Forum Newbie
Posts: 2
Joined: Sat Dec 13, 2003 8:46 pm

Post by PhP T@mer »

OK I have ripped down the script so it just has pure php and no html codes here:

Code: Select all

<?php
$display_template = "<p><COUNTER>: download from <a href='<URL>'><MIRROR> (location: <LOCATION>)</a></p>";

$servers = file ('servers.txt');
for ($i = 0; $i < count ($servers); $i++)
&#123;
  $sarr = explode ('::', $servers&#1111;$i]);
  $sarr&#1111;2] = str_replace ('<FILENAME>', $file, $sarr&#1111;2]);
  $dtmp = str_replace ('<URL>', $sarr&#1111;2], $display_template);
  $dtmp = str_replace ('<MIRROR>', $sarr&#1111;1], $dtmp);
  $dtmp = str_replace ('<LOCATION>', $sarr&#1111;0], $dtmp);
  $dtmp = str_replace ('<COUNTER>', $i + 1, $dtmp);
  echo $dtmp;
&#125;
?>
You can view the script in action here: http://bgw.gtcs.net.nz/genmirlist.php (you will see the error message in bold)

Now to understand how the script works, it works by a user requesting a file to download, such as: http://bgw.gtcs.net.nz/dl.php?file=filesnamehere.zip now the dl.php script is obviously executed and goes to a server.txt file which looks like:

Code: Select all

New Zealand::GTCS::http://bgw.gtcs.net.nz/files/<FILENAME>
And loads the files name along with the location stated in the above txt file, it prints it out as a URL, the user then clicks, and the file downloads.

Now the part which is pruducing the error in the dl.php file is:

Code: Select all

$sarr&#1111;2] = str_replace ('<FILENAME>', $file, $sarr&#1111;2]);
Now this php script works on other servers, so I know that it does definetely work...

The php that is installed on the server is: http://www.php.net/get/php-4.3.4-instal ... m/a/mirror

its for windows....

Does something need to be configured after install on the server?

Any help would be greatly appreciated!

Note: genmirlist.php is the same file as dl.php but without any html codes, genmirlist.php is just pure php.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Instead of using $file, try using $_GET['file']. For more info about $_GET check out this link.
PhP T@mer
Forum Newbie
Posts: 2
Joined: Sat Dec 13, 2003 8:46 pm

Post by PhP T@mer »

You are a hero DuffMan!! It Works!! Thank you so much for you patince and help!
Post Reply