Need help with a Download tracker

well the data is properly being logged into the database now, now i have no clue how to then begin the download because my ftp server is secured by username and password, im completly lost. this type of link doesnt work:
ftp://username:password@mysite:2121/file.mp4

is there any php code that could login download the file and logout with a passive ftp connection?

I already tried this and it doesnt work:

[code]<?php

// define some variables
$local_file = ‘local.zip’;
$server_file = ‘server.zip’;

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo “Successfully written to $local_file\n”;
} else {
echo “There was a problem\n”;
}

// close the connection
ftp_close($conn_id);

?>[/code]

Oooooh, this is a bad issue… Been there many times helping others.

First, FTP is File-Transfer-Protocol. This means it is used for transferring files to SERVERS. Not for downloading to a client. (CLIENT-SIDE means BROWSER)

So, you have to use a standard download system or use a plug-in that handles it inside the BROWSER.
To download in a normal manner, you just link to the file. You can hide the link in a PHP page and call it, but, you can not FTP to a browser. (For instance, my laptop does NOT have an FTP server running on it, so I can not use any form of FTP to download to it.)

Here is a link that says you can send the file thru PHP. I have not tested it. Note that the file name would have to be a full path such as “\data\movie\other-folder-names\movie1.avi” or whatever… might work:
http://psoug.org/snippet/PHP-Download-File-To-Client_53.htm

On this site they show how to do it in PHP by creating an OBJ and flushing it to the browser which will then download the file. Look at response #2 on the page:
http://www.webdeveloper.com/forum/showthread.php?111312-Client-side-download-of-server-file

And, here is a tutorial type post that is very nice and easy to understand. Basically, the same as above, note the location is the full address on your site relative to where the PHP file is. If you do not understand that, I can explain further. Also, remember, if your PHP code is running on your server, it does not need to use FTP as it is already on the server. It just has to “push” the file to the browser. It is similar to a user clicking on a direct link to the file and the file downloads. (Just forces it to start behind the scenes. Since it is in PHP, no client can see your code, so you can use the PHP code to load the real file name from the DB using the movie’s ID and the location of the movie can be there too. (If you are downloading other files, replace the word movies… LOL) Hope this all helps! :
http://webdesign.about.com/od/php/ht/force_download.htm
(Note, you only need to add this code to you tracking code at the end of it. This “pushes” the header and file info to the browser and forces a download.)

Hope that all makes sense…

thanks, i will check out all those links, but for reference my ftp is actually handled by a different server, 1 server has my site on it and a seperate pice of hardware has the files on it, … dunno if that makes things a bit more difficult…

Well, let’s explain a little further… FTP really means UPLOADING to a server. So you can go from a FTP server to another FTP server or you can run a program on a computer that is a FTP-CLIENT that will upload/download with the FTP server.

You can NOT go from a FTP server to a browser. That is not allowed as it is not secure.

But, you can download any file FROM a server to a browser using a link. In that manner, the user of the browser must start the download and that is considered secured.

Another thing to always remember… PHP is SERVER-SIDE only. It doe NOT exist in the CLIENT-SIDE. You will NEVER see PHP code if you VIEW-SOURCE of a page. It only exists on the SERVER-SIDE. So, it can not run FTP commands onto a browser client. (Nothing at the client-side to handle the download.)

But, you can START a download and use headers to start it and the browser will give you the BROWSE dialog for you to tell it where to save the file. So, that is secure because the user (client-side) can cancel it.

Hope all that makes sense. I would start with the last link as it explains it best, I think… Good luck…

well the tracking part of my quest is done, and because the ftp link is an entirely different cunundrum in it self, I would like to say thank you for all your help MR Alex, you have been a tramendous help, that I wish I could pay you for your time, maybe they shuld add donate links under the profile pics on this forum… just an idea. but before I ramble on too much please concider this issue closed and thank you once again!!! :slight_smile: :slight_smile: :slight_smile:

Good for you! And thanks for your comments. But, this is a free help site. I am glad to help.
(We do have a Karma thingy to click on to boost a helper’s level. Does not work for new members!)

The links I sent to start the download is basically a few lines you would add to the tracking PHP code
after it updates the database and it should start the download for the user. (Sending the headers…)

If you can’t figure it out, open a new post with the correct subject and we can help you with it…

Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service