PHP - Files from folder on a webpage -
Jantjuh - 21.02.2011
Edit: Thanks guys (Kwarde) it is working now!
Hey guys,
I'm using the following PHP script:
Код:
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<u><a href=\"$file\">$file</a></u><br />";
}
}
closedir($handle);
}
?>
This script will show the files from the directory called: 'uploads' on a webpage. But now I have a problem. When I click a file in the list, Internet says: Not found. But when I go to the path of the file (
www.blahblah.com/upload/blahblah.jpg) Then it DOES work :S
Does anybody know how I can edit this script so it will download the file whem you click it?
Thanks!
-J
Re: PHP - Files from folder on a webpage -
viKKmaN - 21.02.2011
Try:
Код:
echo "<u><a href=\"uploads/'.$file.'\">$file</a></u><br />";
Or:
Код:
echo "<u><a href=\"'.$file.'\">$file</a></u><br />";
Re: PHP - Files from folder on a webpage -
Jantjuh - 21.02.2011
Quote:
Originally Posted by viKKmaN
Try:
Код:
echo "<u><a href=\"uploads/'.$file.'\">$file</a></u><br />";
Or:
Код:
echo "<u><a href=\"'.$file.'\">$file</a></u><br />";
|
ah, so you mean:
Код:
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<u><a href=\"'.$file.'\">$file</a></u><br />";
}
}
closedir($handle);
}
?>
hmmm, that doesn't work too, thanks anyway!
-J
Re: PHP - Files from folder on a webpage -
viKKmaN - 21.02.2011
What about this... I know your problem is with parsing $file into the echo... Just can't figure out why...
Код:
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<u><a href=".$file.">$file</a></u><br/>";
}
}
closedir($handle);
}
?>
Re: PHP - Files from folder on a webpage -
Jantjuh - 21.02.2011
Quote:
Originally Posted by viKKmaN
What about this... I know your problem is with parsing $file into the echo... Just can't figure out why...
Код:
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<u><a href=".$file.">$file</a></u><br/>";
}
}
closedir($handle);
}
?>
|
nope... too bad it isn't possibble in HTML because that would be freakin simple :P
thanks!
Re: PHP - Files from folder on a webpage -
saiberfun - 21.02.2011
PHP код:
<?php
$files = "http://dl.foco.co/samp/sa-mp-0.3c-install.exe";
echo "<u><a href=".$files.">$files</a></u><br/>";
?>
works fine for me
dunno what your problem is though it
must be a problem with your $files variable
Re: PHP - Files from folder on a webpage -
Jantjuh - 21.02.2011
Quote:
Originally Posted by saiberfun
PHP код:
<?php
$files = "http://dl.foco.co/samp/sa-mp-0.3c-install.exe";
echo "<u><a href=".$files.">$files</a></u><br/>";
?>
works fine for me
dunno what your problem is though it
must be a problem with your $files variable
|
Thanks for your quote!
So should I add my
http://www.blahblah.com/uploads/ line in this:
Код:
$files = "http://dl.foco.co/samp/sa-mp-0.3c-install.exe";
??
Thanks!
Re: PHP - Files from folder on a webpage -
saiberfun - 21.02.2011
Quote:
Originally Posted by Jantjuh
|
no it was just a test if inserting variables in href works^^
Re: PHP - Files from folder on a webpage -
Jantjuh - 21.02.2011
Quote:
Originally Posted by saiberfun
no it was just a test if inserting variables in href works^^
|
Oooh lol
Re: PHP - Files from folder on a webpage -
JaTochNietDan - 21.02.2011
Well, where do the links take you?
pawn Код:
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<u><a href=\"uploads/$file\">$file</a></u><br />";
}
}
closedir($handle);
}
?>
Works as intended for me.
The problem with your original code is that you're pointing to the root directory of the file that contains this code, but the files you're linking to are actually contained in the uploads subdirectory. So you need to point in there, someone else actually posted this solution earlier, but you ignored it