mdub2112 Posted December 8, 2006 Share Posted December 8, 2006 Seems like I have the same problem this gent hadhttp://www.phpfreaks.com/forums/ind...;prev_next=prevOnly problem is that when I try to do what resolved his issue, it does open the correct file, only all garbledIf I go straight with fopen I get output to the browser like below.e.g.[color=orange][color=red]Low � A Client has a problem to which only affects them and does not affect workflow. An issue of a �Low Severity� would be something to the likes of: �My mouse[/color][/color] is what with a Word Doc[color=orange]��A��1��`��RL�EX�]цX3E��q.4aUC���uJ��pce�G*��k&蒻u]��u�(.A�A����*煃�6B�sNgq77��w�A3`0ウX��5FC�L:���w[/color] is what I get for imagesIf I go with all the headers and then fopen, I get the same results as if I used readfile, to which both seem to not work for me. With the headers, the file that seems to be sent, is (with a Word file) showing the html head tags in my download.php script.Any help would truly be appreciated. Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/ Share on other sites More sharing options...
Caesar Posted December 8, 2006 Share Posted December 8, 2006 Are you trying to open locally on the server using relative paths? Or are you using absolute paths?Check your php.ini settings for the following value: "allow_url_fopen = On" Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137636 Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 What are you trying to do? And how are you doing it?Image and Word files can not be displayed on the browser without telling the browser that the contents are not text.Ken Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137639 Share on other sites More sharing options...
mdub2112 Posted December 8, 2006 Author Share Posted December 8, 2006 Download Link Code[code] echo "<a href=download.php?id={$uploads['id']}> {$uploads['title']}<br /> </a>";[/code]download.php script[code=php:0]<title>Downloading....</title><link href="../css/emt_external.css" rel="stylesheet" type="text/css"><div id="global"><?phpinclude_once('db_depot.php');$handle = db_connect();$uploaded = $_REQUEST['id'];$query = "select id, name, type, size from uploads where id = $uploaded";$result = $handle->query($query); if (!$result) { echo "There was a database error when executing <pre>$query</pre>"; echo mysqli_error(); exit; } while ($file = $result->fetch_assoc()) { $file = $file['name']; $type = $file['type']; $size = $file['size']; $path = $file['path']; if(!is_readable($file)) { die("$file does not exist or is not readable"); } else { //echo "$filepath is readable and does exist"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-type: ' . $type); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); header('Accept-Ranges: bytes'); header('Content-Length: ' . $size); //readfile($file); $dir = opendir($path); $handle = fopen($file, 'r') or die('couldnt open file'); $contents = fread($handle, filesize($file)) or die('couldnt read file'); fclose($handle); echo $contents; } } exit;?></div>[/code]The outcome to this is the same as if I comment out the code below the readfile (to which is now commented out).The files are being uploaded (successfully) to /var/www/uploads, the path info is stored in the MySQL Dbase. Currently I have the path stored in one column, and the filename in another with the path attached (/var/www/uploads/filename.ext). Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137643 Share on other sites More sharing options...
mdub2112 Posted December 8, 2006 Author Share Posted December 8, 2006 [quote author=Caesar link=topic=117889.msg481265#msg481265 date=1165604706]Are you trying to open locally on the server using relative paths? Or are you using absolute paths?Check your php.ini settings for the following value: "allow_url_fopen = On"[/quote]Just checked this... set to on Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137644 Share on other sites More sharing options...
kenrbnsn Posted December 8, 2006 Share Posted December 8, 2006 A few comments on your code, which may or may not have any relevence to your problem.1) You use the variable "$file" for two different purposes, once as the array holding the results of the qb query and once to hold the actual filename. Change one or the other variable.2) You have "$dir = opendir($path)", but I don't see where you use the variable anywhere.If you're using Firefox, I would recommend getting either the firebug or livehttpheaders extensions. Either extension will show the headers being returned by your script.Ken Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137650 Share on other sites More sharing options...
mdub2112 Posted December 8, 2006 Author Share Posted December 8, 2006 [quote author=kenrbnsn link=topic=117889.msg481279#msg481279 date=1165606013]A few comments on your code, which may or may not have any relevence to your problem.1) You use the variable "$file" for two different purposes, once as the array holding the results of the qb query and once to hold the actual filename. Change one or the other variable.2) You have "$dir = opendir($path)", but I don't see where you use the variable anywhere.If you're using Firefox, I would recommend getting either the firebug or livehttpheaders extensions. Either extension will show the headers being returned by your script.Ken[/quote]Ya, I had tried something else, to which is where the opendir came from and I forgot to remove it prior to posting (it's not in the script right now, but no diff). I am using Firefox, just might have to do that, seems the downloads (when using the headers with readfile or fopen) are getting the correct info as it knows it's a gif, jpg, doc, pdf, zip, etc... I was wondering about that second occurance of using $file. I did change that and it didn't seem to help. Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137655 Share on other sites More sharing options...
mdub2112 Posted December 8, 2006 Author Share Posted December 8, 2006 Anyone else with any ideas? Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137734 Share on other sites More sharing options...
mdub2112 Posted December 8, 2006 Author Share Posted December 8, 2006 I've got this so it is working with TEXT files; however, not anything else.Is there a setting somewhere that would disallow other types? Link to comment https://forums.phpfreaks.com/topic/29960-neither-readfile-or-fopen-are-working/#findComment-137758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.