Jump to content

File Management


Wayneio

Recommended Posts

Hi,

 

I am very new to PHP, I have managed to create a basic database with a table of users, and a form for logging in.

 

Is there a way to create an 'area' where the users that are logged in can view, upload and download files. For example, a file storage area just like dropbox? If so, can anyone share some basic code or links to tutorials to achieve this please.

 

Afterwards, I would then like to set permissions for each of the users to only access certain folders within that 'storage area'.

 

I realise there are many websites like dropbox and box.net, but I would like to code my own version.

 

Thanks in advance

Link to comment
Share on other sites

This is possible but it is not simple task.

Users shouldn't have direct access to uploaded files.

Every file / (imaginary)directory should be paired with user that needs access them.

Access should be realized through script which checks does user owns rights to requested file ...

Link to comment
Share on other sites

Thanks for your reply.

 

My idea was to have access levels for groups of users, such as:

 

Main folder - Journalists can upload / download

Edited folder - Editors can upload / download / move between folders

Final folder - Proofers can upload / download

        -Admins can access all folders

 

This could be done with mysql access levels, but the main thing I need a tutorial / code for, is the uploading, viewing and deleting of files (initally for any user)

 

 

Link to comment
Share on other sites

Hi

 

That is more a php than mysql issue.

 

File uploads are not that complicated and there are loads of tutorials online. Essentially you have a form with enctype='multipart/form-data' and an input field of type file. This lands up in the $_FILES array in php, which is an array (of files) of arrays (of details of a file). You loop through that, checking the files a required and then move the file from the tmp_name array key to where you actually want it stored (which should be outside any web accessible directory).

 

You then have a script to produce the file on demand, which uses something like the following:-

 

header('Content-Length: ' .filesize($FullFilePath));
header("Content-Type: image/jpeg");
readfile($FullFilePath);

 

to set the length of the output, the file type of the output and then copy the saved file out.

 

Note that you can (and probably should) store the files with a random name, and have a database table entry linking the random name to the real name (means duplicate names are not a problem, and also means that even if someone does get access to the files directly they are delayed a bit by meaningless names).

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.