We have successfully created code for uploading files to a site and
moving that file to an A4D-aware directory.  Now we want to download
it back to the user as a link.  Can someone give me some sample code
to do this?

I assume that we need to copy the file into a variable and send that
to the browser, but I'm not sure how to get started.

I've done this with PHP by using:

                $dir="download/files/";
                $filename = $_REQUEST["file"];
                $file=$dir.$filename;
        
                // Test to ensure that the file exists.
                if(!file_exists($file)) die("I'm sorry, the file doesn't seem to 
exist.");
                // Extract the type of file which will be sent to the browser 
as a header
                $type = filetype($file);
                $size = filesize($file);

                ob_clean();                     //      clean the output buffer 
of any crap

                // Send file headers
//              header("Content-type: $type");
                header("Content-Type: application/force-download; 
name=\"$filename\"");
                header("Content-Transfer-Encoding: binary");
                header("Content-Length: $size");
                header("Content-Disposition: attachment; 
filename=\"$filename\"");
                header("Expires: 0");
                header("Cache-Control: no-cache, must-revalidate");
                header("Pragma: no-cache");

                // Send the file contents.
                set_time_limit(0);
                readfile($file);
                exit;

But in a4D, I can't seem to get the file into a variable correctly.

Thanks!

Michael Check
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to