Page 1 of 1
[SOLVED] PHP Scripting Problems
Posted: Thu Dec 11, 2003 2:52 am
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
Posted: Thu Dec 11, 2003 3:24 am
by twigletmac
Could you do us a favour and post lines 50 - 65 of dl.php.
Mac
Posted: Thu Dec 11, 2003 4:13 am
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.
Posted: Thu Dec 11, 2003 4:18 am
by JayBird
which of those lines in actually line 60?
Mark
Posted: Thu Dec 11, 2003 6:54 pm
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.
Posted: Thu Dec 11, 2003 7:50 pm
by DuFF
Well do you actually have the variable $file defined somewhere in the script? If not, this is your problem.
Posted: Sat Dec 13, 2003 8:46 pm
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++)
{
$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;
}
?>
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ї2] = str_replace ('<FILENAME>', $file, $sarrї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.
Posted: Sat Dec 13, 2003 10:20 pm
by DuFF
Instead of using $file, try using $_GET['file']. For more info about $_GET check out
this link.
Posted: Mon Dec 15, 2003 1:12 am
by PhP T@mer
You are a hero DuffMan!! It Works!! Thank you so much for you patince and help!