Consolidate 50 db connection / download files into 1

sorry to ask this guys, but I’m starting to produce the site I’ve been talking about here for months. I have the following subdirs, as an example:

1/
2/
3/

and in order to save my time and test, for the first time, what I want to do, I have, in each of those subdirs, these 3 entities:

dl.php
conn.php
file.extension

the DL file is accessed by clicking on a link in the parent dir, the CONN file connects to the DB, and then the file is downloaded.

Question for you folks => how do I get this done for those 50+ subdirs, using only 1 DL file and 1 CONN file? Hint anyone? thanks!

Adam

This makes no sense. Tell us what the REAL problem is you are trying to solve by doing this.

What is the high level overview of what you have going on?

I realize it doesn’t make any sense ben, however what you guys probably don’t realize is that I’m more of a manager of coders rather than a coder himself. And therefore I write software just like any vendor of the world does when they sell the large corporations that are looking to buy cheap stuff. just simply repetitive nature over and over and over again rather than spending years trying to figure out the most efficient manner possible. Does that make sense?

Essentially what I have right now since you asked, is 50 directories that have one final piece in them and I’m offering them for download to certain people at the moment and the directory is password protected using a hosting company tool. And the security will change when I start to implement the http domain level security that was given to me by @astonecipher many months ago. However I don’t have time to do that at the moment.

So that’s the reason I’m asking the question. Because when I have right now obviously is totally not efficient and it’s not even using a database it’s just storing the download counts and IP addresses for people that download the files in the database but like I said there’s 50 different files all of the same name. Is that what you’re looking for?

It sounds like your users navigate to dl.php in each directory. What does dl.php do?

no they don’t. they click on a link on a page called index.php, and the link points to the file to be downloaded using GET. here’s the code in DL:

<?php
// Error reporting:
error_reporting(E_ALL^E_NOTICE);
// Including the connection file:
require('conn.php');
if(!$_GET['f']) error('Missing parameter!');
        $stmt = $conn->prepare("INSERT INTO tblDownloads (ip, file, date, time) 
        VALUES (?, ?, ?, ?)");
        $stmt->bind_param("ssss", $ip, $file, $date, $time);
        $stmt->execute();
        $stmt->close();
        $conn->close();
            header("Location: FILE_TO_BE_DOWNLOADED.EXTENSION");
            exit;
?>

here is partial code in the index.php file:

<?php
include("../r/pagevisit.php");
?>
<html>
<body>
<ul>
<li><a href="SUBDIR_NAME\dl.php?f=FILE_NAME.EXTENSION" target="_blank">A_TAG_DISPLAY_TEXT</a></li>

Ok. So you’re showing a directory listing on index.php, and using dl.php to record the download times and details of each file before forwarding the user to the file itself. Is that right?

well, yes obviously. the query is running before executing HEADER. so that pretty much answers your question, doesn’t it? the answer is YES. I’m no PHP expert, but that’s exactly what it looks like I’ve set up.

I’m still not positive what you’re trying to do but it sounds to me like you want to recurse through the directories to get the file names and then use relative pathing to offer the download links and consolidate the 2 other repeat files.

sort of @anaror. What I want is a universal link so I can let a user click on each link in each directory, which are all meant to store different types of files to download. each dir has a link to the file to be downloaded. thus, when a user goes into any directory to download the file they want, they simple click on the link and the code I want behind the download link should be the same for every dir, just with a param changing (or whatever you call it. spec? argument? parameter? query string?). something like this…

<a href="SUBDIR_NAME\dl.php?f=FILE_NAME.EXTENSION&dir=directory_1"

do you see what I’m asking now? or should I show an actual sample on my site to you guys? I can do that if need be.

Yeah, I still don’t get it.

Well, why would you want to store 50 files in 50 different folders and have such a horribly complicated system just to download a file? Just put them all in one folder and display the links to them on a page.

I think we do not understand why you would do this type of system. If you need some sort of security on the files, for instance to only let some users download certain files and other not, well, just do that in the user-table when they log on so they can only see the ones they are allowed to download. I think we are confused about the overview of what all this really does.

1 Like

Ernie,

I don’t need security for users. anyone can download any of these files. however, I DO have the parent level dir, where the links are given, password protected using Godaddy’s cPanel tool. That isn’t the best, but it works fine as of now.

The entire point of all of this, and the reason this thread exists at all is for many reasons:

- I do not have the time to dev this site in its entirety at the moment, but I need these downloadables available immediately.

- I do not have a lot of experience in dynamic website creation and using databases for up-to-date purposes like what you’re describing (although I CAN do it).

- I am more of a manager rather than a coder, and thus I write code in the most repetitive manner possible, which is always not the most ““professional”” method used by developers like yourselves.

do you guys want to see an example of what I have done? I can create a test dir if you would like…

Well, you could create a script to read all the folder’s and list the filenames on a page. That is easy to do.
If you want to do that, you can use this type of routine. Not a finished product, just a starting point…

$files = new RecursiveTreeIterator(new RecursiveDirectoryIterator("/path/to/dir",RecursiveDirectoryIterator::SKIP_DOTS));
foreach($files as $path) {
  echo $path."<br>";
}

You would need to pull out the ones you need by checking the extensions and display them however.

I don’t understand most of that, Ernie. But I’m sure I can look it up and adopt it as I need it. Most is not difficult anyway. give me some time to implement, and I’ll get back to you here when I need a push. thanks.

You are welcome. I will explain just a little…

You can create a recursive function to loop thru all your folders, but it does get tricky. Since PHP5.3, they added this newer command which does it for you. Make life much easier. The one problem with recursion into folders is the “.” and “…” entries which point at the previous folder levels. The SKIP:DOTS in that example skips these so they do not end up in the filename list. The only thing you need to change is the path-to-folder and what you want done with the pointers to each filename. I am sure you can sort it out. Good luck!

that’s incredibly pathetic Ernie. you know what that does don’t you? It creates a world where no one needs to know anything in order to make millions. I find corporations very sick in that regard. but then again, since they technically are ““the machine””, things can progress no other way. =(

I will let you know how I get on.

It turns ten lines of spaghetti into three. Most of us deal with tens of thousands of lines of code, and will take as many opportunities like that as we can get. :slight_smile:

1 Like

Ha! Always enjoy how programmers see their own worlds. I see it this way…

You can build ANYTHING with the right tools! This tool is handy… Well, has been for me!

that may be true but if you’re dealing with tens of thousands of lines of code then obviously you work for a large corporation because no small business or medium-sized business would require that of someone like you.

Furthermore since the concept of low code and no code is becoming so prevalent eventually your job is going to become very very easy and you’ll be bored to tears but I’m sure you know that’s coming. pretty soon you guys will be nothing more than just people sitting in cubicles waiting for things to break like all of the server administrators and sitting in the dungeons across the world have been doing for 20 years lol :slight_smile:

If I was your manager Ernie you would see programmers come together and learn tremendously :slight_smile: that’s the gift I have for you people

Sponsor our Newsletter | Privacy Policy | Terms of Service