Derek Posted August 13, 2010 Share Posted August 13, 2010 So, I'm trying to write a download script for my site by using the "Content-disposition" header. However, in order for it to work, I have to supply the file's MIME type. So I wrote it to automatically check for the file's type using finfo, so different files could still be downloaded. Then I got: Fatal error: Call to undefined function finfo_open() According to PHP.net, I found it's because the PECL extension is not installed. So, please install it, because I would love to get this to work. Thanks, ~Derek Extra Info: Username: derekboy Site: unorthodox.co.cc PHP Source: <?php /* The equivalent code: * * header('Content-disposition: attachment; filename=someFile.ext'); * header('Content-type: madeUp/MIMEtype'); * */ $filename = $_GET['file']; $fileinfo = finfo_open(FILEINFO_MIME_TYPE); chdir("download"); header('Content-disposition: attachment; filename=' . $filename); header('Content-type: ' . finfo_file($fileinfo, $filename)); readfile($filename); ?> Link to comment Share on other sites More sharing options...
Byron Posted August 13, 2010 Share Posted August 13, 2010 This support request is being escalated to our root admin. Link to comment Share on other sites More sharing options...
Derek Posted August 13, 2010 Author Share Posted August 13, 2010 Alright thanks, and sorry for posting in the wrong section--the FAQ said to post it here. Link to comment Share on other sites More sharing options...
Wizard Posted August 13, 2010 Share Posted August 13, 2010 Alright thanks, and sorry for posting in the wrong section--the FAQ said to post it here. That was the right forum to post in. Link to comment Share on other sites More sharing options...
Derek Posted August 13, 2010 Author Share Posted August 13, 2010 Oh sorry--when I saw "Moved" I just assumed. I hadn't realized it was moved to "Escalated Requests". Link to comment Share on other sites More sharing options...
Ashoat Posted August 13, 2010 Share Posted August 13, 2010 The PECL extension is certainly installed. root@stevie [/usr/local/apache/logs]# pecl version PEAR Version: 1.9.1 PHP Version: 5.3.3 Zend Engine Version: 2.3.0 I don't suppose you mean a particular PECL extension? PECL is a PHP extension installer. Link to comment Share on other sites More sharing options...
Byron Posted August 13, 2010 Share Posted August 13, 2010 I don't suppose you mean a particular PECL extension? PECL is a PHP extension installer. I think what he's really wanting is for this particular function to work. finfo_open() Link to comment Share on other sites More sharing options...
Ashoat Posted August 13, 2010 Share Posted August 13, 2010 Ah, okay. That appears to be in the "fileinfo" extension. I tried to install it, but the ./configure failed, and the installer said it was deprecated for a compiled PHP extension. Link to comment Share on other sites More sharing options...
Byron Posted August 13, 2010 Share Posted August 13, 2010 @Derek Exactly what info do you need from a file? Would this work? http://www.php.net/manual/en/function.curl-getinfo.php Here's an example of what kind of info you can get with curl_getinfo. Just enter a url in the form and submit. http://byrondallas.heliohost.org/php/tools/curl_get_info.php EDIT: Here's a list of functions that we do support: http://byrondallas.heliohost.org/php/get_d...d_functions.php Link to comment Share on other sites More sharing options...
Derek Posted August 13, 2010 Author Share Posted August 13, 2010 @Derek Exactly what info do you need from a file? Well, extending on what I said on the original post, I'm writing a download script that takes the file name from the url, so if I wanted to download my test.txt, I would go to "download.php?file=test.txt" <?php $filename = $_GET['file']; //Get the file name using the variable "file" in the URL chdir("download"); //Files to download are in my public_html/download folder header('Content-disposition: attachment; filename=' . $filename); //Force the browser to download file, not view it. header('Content-type: text/plain'); //This would only work for test.txt readfile($filename); ?> So, the 4th line is telling the browser what MIME type the file is, so this example would work fine, but if I tried to download, lets say, a Zip folder, it would be telling the browser that it's a text file, and it thinks it's supposed to be saved as a .txt extension. That's what I needed the finfo_*() functions for--it would give me the MIME type of any file being used for $file, so it would save as a .zip, for example, instead of a .txt. EDIT: Yeah, byron, I checked that example you gave me and it looks like I could use it, but it returns a lot of data when I really only need the "Content-Type" part of it, so I'll read more on those PHP.net pages you linked. Link to comment Share on other sites More sharing options...
Byron Posted August 13, 2010 Share Posted August 13, 2010 Returns only the content type: <?php $ch = curl_init("http://byrondallas.heliohost.org/audio/budtotal.wav"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLINFO_EFFECTIVE_URL, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); # For this example, just discard the output. $src = curl_exec($ch); # Get all information about the transfer. $extract = curl_getinfo($ch); # Echo only the content type echo $extract['content_type']; # Clean up. curl_close($ch); ?> http://byrondallas.heliohost.org/test/Curl-url-info.php Link to comment Share on other sites More sharing options...
Derek Posted August 13, 2010 Author Share Posted August 13, 2010 Cool, thanks. It works just like I needed. I guess I didn't need finfo at all Link to comment Share on other sites More sharing options...
Ashoat Posted August 14, 2010 Share Posted August 14, 2010 Awesome, glad you got it figured out Link to comment Share on other sites More sharing options...
Recommended Posts