I'm uploading files via php script straight to a folder called 'uploads' on my mysql server.
I can list all the files uploaded.
My problem is listing only selected files from this folder for each user that login.
i.e. user A logs in with username 'theboss'
The user will be directed to a page where only the files in the folder 'uploads' starting with 'theboss_****' will be retrieved and listed.
The user should then be able to select the file/s he wants to download to his PC.
Any help will be greatly appreciated.
4x4

Recommended Answers

All 7 Replies

When the user logs in, add his username to the session and append the username to the upload directory and list the files.

When the user logs in, add his username to the session and append the username to the upload directory and list the files.

Hi nav
Thanks for the help.
This is my first time with PHP and I'm a bit stuck again.

Where do I add the username and append the username to the upload directory?
This is the link to the php script: http://www.surveywarehouse.com.na/multiple_upload_ac.php

When listing the files, i use the following script that makes the files URL links.
Where do I add the username?
This is the link to the php script: http://www.surveywarehouse.com.na/listfiles_withlink.php

Thanks
Willie

When the user logs in, add his username to the session and append the username to the upload directory and list the files.

Hi nav
Thanks for the help.
This is my first time with PHP and I'm a bit stuck again.

Where do I add the username and append the username to the upload directory?
This is the link to the php script: http://www.surveywarehouse.com.na/multiple_upload_ac.php

When listing the files, i use the following script that makes the files URL links.
Where do I add the username?
This is the link to the php script: http://www.surveywarehouse.com.na/listfiles_withlink.php

Thanks
Willie

since the user should be logged in to upload files, why don't you just put the uploaded file name into the database with their user id. then all you have to do to get the files for a certain user by one simple query: SELECT * FROM `files` WHERE `id` = 'user_id_goes_here'

Hi kk
The problem I have is that an admin account user will add the files to the server folder. The user will login in and will be shown just the files that correspond to his username.
W

Umm..so, for example, if the admin uploads a file called "naveen_1.txt" and "naveen_2.txt" , If I log in (with username naveen), then it has to list only these 2 files ?
If that's the case, then open the dir(where the uploaded files are placed) , check if the username (naveen in this case) is a part of the filename and list those files.

Thanks again Naveen

Can you assist me in checking to see if username is part of the filename?
The script follows:

<?php

$folder = "upload/";
$handle = opendir($folder);

# Making an array containing the files in the current directory:
while ($file = readdir($handle))
{
$files[] = $file;
}}
closedir($handle);
?>

<p align="center"><font face="Verdana" style="font-size: 8pt"><b>The following files are available:</b><br>
Click on the file, then select "Save" from the list.</font></p>

<p align="center"><font face="Verdana" style="font-size: 8pt">
<?php
foreach ($files as $file) {
echo "<a href=$folder$file>$file</a>"."<br />";
}
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.