Flat download script attempt

Started on the old forum in September 2010 · view the original in the archive · old links redirect here

2 replies · 765 views · started 16 years ago · 1 min read

Guest #1

Hello this is my first attempt at a flat download script but how would i make it scan directories and download the downloads on a new page instead of that same page ? or any other features that come on todays standard download scripts.

Please consider that i am still new to programming so please explain any code that you post if you dont mind thanks

///////////////////////////This is my index.php of the downloads script :

<?php include("core.php"); for($i = 0; $i < count($files); $i++) { $files = str_replace(" ", "%20", $files); if(is_dir($files[$i]) | is_dir($filename[$i])){ } else { echo "[$filename[$i]](#)"; $size = round(filesize($filename[$i])/1024); echo " $size" . "KB" . " "; } } for($i = 0; $i < count(is_dir($dir))); $i++) { } ?>

//////////////////////////////////This is my core.php of the downloads script

<?php $dir = getcwd(); $files = scandir($dir); $remove = array("index.php","core.php"); $files = array_diff($files, $remove); $filename = scandir($dir); $remove = array("index.php","core.php"); $filename = array_diff($filename, $remove); $directory = scandir(readdir($dir)); echo "$directory"; ?>

//////////////////////////////////

Please ignore

$directory = scandir(readdir($dir)); echo "$directory";

and

for($i = 0; $i < count(is_dir($dir))); $i++) {

}

i was just messing around to try see if i could make it scan directories...thanks in advanced

Guest #3

Ok thanks ive worked out how to use the get and post method well so ive figured out how to open the download on a new page but now would i use the fopen to scan directories using the get and post method as well ?

Added after 4 minutes:

heres my new script updated

/////////////////////////////////////index.php

<?php $dir = "."; $files = scandir($dir); for($i = 0; $i < count($files); $i++ ){ if(is_dir($files[$i])){ echo "<a href=http://localhost/killerphp/download%20script/file.php?file=" . "$files[$i]" . "&filename=" . "$files[$i]" . ">$files[$i]</a> "; } else { echo "<a href=http://localhost/killerphp/download%20script/file.php?file=" . "$files[$i]" . "&filename=" . "$files[$i]" . ">$files[$i]</a> "; } } ?>

/////////////////////////////////////////////file.php

<?php $file = $_GET['file']; $filename = $_GET['filename']; echo "<a href=/" . "$file" . ">" . "$filename" . "</a> "; ?>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

but now im also having problems with filenames with spaces it doesnt work when the files have spaces in the names is there a function that renames certain characters in an array ? i have looked around but i cant find any functions that replaces a space with %20 in an array

i also tried within the loop to replace the space with %20 using a string replace function but the problem is i get an error

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close