Flat download script attempt

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Flat download script attempt

    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 "<a href=" . "http://localhost/killerphp/download%20script/" . "$files[$i]" . ">$filename[$i]</a>";
    $size = round(filesize($filename[$i])/1024);
    echo " $size" . "KB" . "<br />";
    }
    }

    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

    #2
    http://localhost/killerphp/download script/view.php?f=file_name

    Comment


      #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><br />";
      } else {
      echo "<a href=http://localhost/killerphp/download%20script/file.php?file=" . "$files[$i]" . "&filename=" . "$files[$i]" . ">$files[$i]</a><br />";
      }
      }


      ?>



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

      <?php
      $file = $_GET['file'];
      $filename = $_GET['filename'];

      echo "<a href=/" . "$file" . ">" . "$filename" . "</a><br />";

      ?>

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

      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
      Last edited by Guest; 20.09.10, 08:39.

      Comment

      Working...
      X