Grow your CSS skills. Land your dream job.

Creating a file browser

  • # August 1, 2012 at 6:58 am

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

    < ?php
    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, '
    ';
    }
    }
    }
    }
    ?>
    < !DOCTYPE html>














    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?

    # August 5, 2012 at 12:50 pm

    using opendir()

    example:


    < ?php
    $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)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".