Welcome Guest, Not a member yet? Register   Sign In
Managing downloads
#1

[eluser]Bramme[/eluser]
I've been asked to code a site that'll need a downloads section. I haven't got the specifics yet, but it's a clan site that'll probably contain some large files.

I can imagine I can't use the download helper to force downloads of over 100mb (php memory limit i guess?), but on the other hand, that would be exe files than that get forced anyhow...


Has anybody got any experience with downloads sections?
#2

[eluser]Michael Wales[/eluser]
Don't use the download helper and just link directly to the file?
#3

[eluser]Bramme[/eluser]
Yeah okay, but what if I want to force download jpg's?

The easiest thing to do would probably be to just let them upload anything they want, but implement an if that checks if the filetype is in_array with filetypes that they want forced.

Related question: how would you go about passing paths in your uri? Or should you use some other technique (sessions or whatever)
#4

[eluser]LuckyFella73[/eluser]
Hi Bramme,

you could save pathes in a database. Additionally you could
save needed informations that can help you to manage the
"download type" (a flag -> direct link or force download ..) in the
frontend.

For larger files you could use something like the following script:
Code:
// required for IE, otherwise Content-disposition is ignored
        if(ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');

        // addition by Jorg Weske
        $file_extension = strtolower(substr(strrchr($filename,"."),1));

        if( $filename == "" )
        {
            echo("FILE:  ".$down_name);
            echo "<html><title>Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
            exit;
        }
        elseif ( ! file_exists($filename) )
        {
            echo "<html><title>Download Script</title><body>ERROR: File ($filename) not found. USE force-download.php?file=filepath</body></html>";
            exit;
        }
        switch( $file_extension )
        {
            case "pdf": $ctype="application/pdf"; break;
            case "exe": $ctype="application/octet-stream"; break;
            case "zip": $ctype="application/zip"; break;
            case "doc": $ctype="application/msword"; break;
            case "xls": $ctype="application/vnd.ms-excel"; break;
            case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
            case "gif": $ctype="image/gif"; break;
            case "png": $ctype="image/png"; break;
            case "jpeg":
            case "jpg": $ctype="image/jpg"; break;
            default: $ctype="application/force-download";
        }
        header("Pragma: public"); // required
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false); // required for certain browsers
        header("Content-Type: $ctype");
        // change, added quotes to allow spaces in filenames, by Rajkumar Singh
        header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".filesize($filename));
        readfile("$filename");
Where "$down_name" is the filename and "$filename" ist the path and filename.

BTW: thanks for your auth tutorial - it helped me very much!
#5

[eluser]Michael Wales[/eluser]
For the path in the URI:
Use $this->uri->segment_array(), unset the first two keys (if you're URI is class/method), then implode with a '/' separator.
#6

[eluser]leafc[/eluser]
[quote author="Michael Wales" date="1221566832"]Don't use the download helper and just link directly to the file?[/quote]


I set direct link to PDF file or zip fils to let user downloads file but getting 404 error.
What I'm doing wrong?
#7

[eluser]Colin Williams[/eluser]
If you are linking directly to the files, leafc, then what does CodeIgniter have to do with anything
#8

[eluser]BrianDHall[/eluser]
[quote author="leafc" date="1255130396"][quote author="Michael Wales" date="1221566832"]Don't use the download helper and just link directly to the file?[/quote]


I set direct link to PDF file or zip fils to let user downloads file but getting 404 error.
What I'm doing wrong?[/quote]

Your path is wrong, or you have an .htaccess problem that is preventing direction connection to your file.




Theme © iAndrew 2016 - Forum software by © MyBB