Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Creating a file browser

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39158

    I have made PHP script which allow user to upload files to the site directory:

    
    if (isset($_FILES )) {
    $errors=array () ;
    $allowed_ext= array ('doc','docx','ppt','pptx','pages','html','xls','xlsx','numbers','pdf');

    $file_name= $_FILES ;
    $file_ext= strtolower(end(explode ('.', $file_name)));
    $file_size= $_FILES ;
    $file_tmp= $_FILES ;


    if (in_array($file_ext, $allowed_ext) === false) {
    $errors[] ='Extension not allowed';
    }

    if ($file_size > 3145728) {
    $errors[] ='file size must be under 3mb';
    }
    if (empty($errors)) {
    if (move_uploaded_file ($file_tmp, 'uploads/'.$file_name)) {
    echo 'File uploaded successfully';

    } else {
    foreach ($errors as $errors){
    echo $error, '
    ';
    }
    }
    }
    }
    ?>















    I want to create a file browser that will allow users to view and download the files that are uploaded. How do I do this?

    #107343
    irish1381
    Member

    using opendir()

    example:


    $dir = "/path/to/your/directory/";
    if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
    while (($file = readdir($dh)) !== false) {
    echo "filename: $file : filetype: " . filetype($dir . $file) . "n";
    }
    closedir($dh);
    }
    }
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.