Page 1 of 1

[Add folder]Limit File Download Speed

Posted: Thu Mar 24, 2016 12:21 am
by Musyanon
Hello all !

Thank you very much for your job and all tutorial !
I have followed this tutorial http://betterphp.co.uk/playlist.html?pi ... C5B36B370F
All work perfectly ! But I have a question, is it possible to make folder with files inside to explore it.

example :
all my file is on files folder, and I want create sub folder to this.

link to my script : http://forum.rowproject.com/limit/file_list.php (Test is folder)

Thank you and good night ^^

Re: [Add folder]Limit File Download Speed

Posted: Wed Mar 30, 2016 8:00 pm
by jacek
Hey,

I don't think I'm completely understanding what you're after.

If you're after a folder structure like you might get on something like Dropbox then it's surprisingly hard to do but here goes my explanation :P

There are a couple of ways that I can think of; either use the actual filesystem or store the folder names in a database and the files all in one folder.

Both have their limitations thought. If you're using the actual files you'll be creating and deleting directories on the server which is not a good idea for security reasons really. If you go for the folder names in a database method then it will be pretty tricky get get at a list of files in a certain older path - if you know that folder_1 is inside folder_2 and that folder_2 has a file_1 inside it how would you get to /folder_1/folder_2/file_1 as a database query? very awkward.

I'd go for the filesystem approach I think but be very careful to make sure people can't do things like upload executable files or delete other peoples folders.

The idea is basically that you make the folder that they chose in the folder they are assigned. For example if user_1 wants to put a file in folder_1/folder_2 you might have something like this

[syntax=php]
<?php

$user_root_path = '/var/www/upload/user_files/user_1';
$upload_file_path = 'folder_1/folder_2/file_1';
$stored_file_path = "{$user_root_path}/{$upload_file_path}";

mkdir(basename($stored_file_path));
move_uploaded_file($_FILES['file']['tmp_name'], $stored_file_path);
[/syntax]

Then a bit later you could have a page that displays the files in that folder using scandir()

[syntax=php]
<?php

$user_root_path = '/var/www/upload/user_files/user_1';

foreach (scandir($user_root_path) as $file){
if (is_dir($file)){
// this is a folder entry, show a link to switch to view that
}else{
// this is a file entry, show a link to download it
}
}
[/syntax]

This is the basic idea and has no security at all - you need to make sure people can't use lever file names to write to places they're not meant to. This is not super easy to so and where the database method starts to sound like a better idea.

So yeah, not as simple as it might sound

I'd start with this insecure example and go from there, it's one of those things where you just have to start with no idea and keep changing how it works until it does everything that's needed.

Sorry, don't feel like this was very helpful :(