zeeshan_haider000 Posted March 1, 2009 Share Posted March 1, 2009 Hi everyone lol another quick question: I used ob_start() and then tried to write the buffer data (ob_get_contents()) to a file, but the file isn't being created... here is my script, am i doing anything wrong? Help will be much appreciated, thanks. <?php function GetNohay($cat){ ob_start(); if (isset($_GET['reciter'])){ $reciter = $_GET['reciter']; //**TABLES, FIELDS include_once('config.php'); if (isset($_GET['year'])){ $t = mysql_query("SELECT * FROM column1 WHERE Sng ='".addslashes($reciter)."' AND Year='".addslashes($_GET['year'])."' AND Cat='".$cat."' ORDER BY Year DESC, Sng ASC") or die(mysql_error()); } else { $t = mysql_query("SELECT * FROM column1 WHERE Sng ='".addslashes($reciter)."' AND Cat='".$cat."' ORDER BY Year DESC, Sng ASC"); if(!$t) die(mysql_error()); } $a = mysql_fetch_object($t); $total_items = mysql_num_rows($t); if(isset($_GET['limit'], $_GET['page'])){ $limit = $_GET['limit']; $page = $_GET['page']; } else { $limit = 10; $page = 1; } //set default if: $limit is empty, non numerical, less than 10, greater than 50 if((!$limit) || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 30)) { $limit = 10; //default } //set default if: $page is empty, non numerical, less than zero, greater than total available if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { $page = 1; //default } //calcuate total pages $total_pages = ceil($total_items / $limit); $set_limit = $page * $limit - ($limit); if (isset($_GET['year'])){ $q = mysql_query("SELECT * FROM column1 WHERE Sng ='".addslashes($reciter)."' AND Year='".addslashes($_GET['year'])."' AND Cat='".$cat."' ORDER BY Year DESC, Sng ASC LIMIT $set_limit, $limit") or die(mysql_error()); } else { $q = mysql_query("SELECT * FROM column1 WHERE Sng = '".addslashes($reciter)."' AND Cat='".$cat."' ORDER BY Year DESC, Sng ASC LIMIT $set_limit, $limit"); if(!$q) die(mysql_error()); } $err = mysql_num_rows($q); if($err == 0) die("<table border='0'><tr><td><b style='color: #000000;'>No matches met your criteria.</b></td></tr><tr><td><input type='BUTTON' value='Go Back' style='border: none; color:red;' onClick='history.go(-1)'></tr></td></table>"); //Results per page: ** LINK PATH** echo("<div class='mpages'> <table border='0'><tr><td>Page <b>".$page."</b> of <b>".$total_pages."</b></td><td>-</td><td> View per page:"); if ($cat =='nohay'){ echo (" <a href='nohay.php?reciter=$reciter&limit=10&page=1'>10</a> | <a href='nohay.php?reciter=$reciter&limit=20&page=1'>20</a> | <a href='nohay.php?reciter=$reciter&limit=30&page=1'>30</a></td>"); } else { echo (" <a href='majlis.php?reciter=$reciter&limit=10&page=1'>10</a> | <a href='majlis.php?reciter=$reciter&limit=20&page=1'>20</a> | <a href='majlis.php?reciter=$reciter&limit=30&page=1'>30</a></td>"); } echo ("<td>-</td><td>Year: </td><td><form action='".PageUrl()."' method='get' name='form1'><select name='year' style='font-size:10px;' onchange=\"this.form.submit();\">"); $year = date('Y'); for ($a=2000; $a<=$year; $a++){ echo "<option value='".$a."'>".$a."</option>"; } echo "</select></td><td><input type='hidden' name='reciter' value='".$_GET['reciter']."'></form></td>"; echo ("</tr></table></div>"); //show data matching query: while($row = mysql_fetch_array($q)) { echo ("<div class='container'>"); $file2 = "http://site.com/sitev2/download.php?reciter=".urlencode($row['Sng'])."&cat=".urlencode($row['Cat'])."&ftype=".urlencode($row['FileType'])."&id=".urlencode($row['Id'])."&year=".urlencode($row['Year'])."&file=".urlencode($row['Link']).".".urlencode($row['FileFormat'])."";//download link echo ("<img src=\"/sitev2/images/".$row['FileFormat'].".gif\">"); echo (" <a href='http://site.com/sitev2/download.php?reciter=".urlencode($row['Sng'])."&cat=".urlencode($row['Cat'])."&ftype=".urlencode($row['FileType'])."&id=".urlencode($row['Id'])."&year=".urlencode($row['Year'])."&file=".urlencode($row['Link']).".".urlencode($row['FileFormat'])."'>".$row['Topic']."</a>"); echo "<div class='clear'></div>"; echo ("<div class='small'>"); echo ("Year: <b>".$row['Year']."</b> | Language: <b>".ucfirst($row['Language'])); //get size of the file echo "</b> | File size: <b>"; $file = "".$row['FileType']."/".$row['Cat']."/".$row['Sng']."/".$row['Year']."/".$row['Link'].".".$row['FileFormat'].""; if (file_exists($file)){ $file = filesize($file); $file = round($file/1048576); if ($file < 10){ echo "0".$file." MB"; } else { echo $file." MB"; } } else { echo "00 MB"; } echo ("</b> | Downloads: <b>".$row['Hits']." |</b> <img src=\"images/download.gif\"> <a href='download.php?reciter=".urlencode($row['Sng'])."&cat=".urlencode($row['Cat'])."&ftype=".urlencode($row['FileType'])."&id=".urlencode($row['Id'])."&year=".urlencode($row['Year'])."&file=".urlencode($row['Link']).".".urlencode($row['FileFormat'])."'>Download</a>"); //mp3 player code start if ($row['FileFormat'] == 'mp3'){ $path = "".$row['FileType']."/".$row['Cat']."/".$row['Sng']."/".$row['Year']."/".$row['Link'].".".$row['FileFormat'].""; //Mp3 File Path echo " | <a href='http://www.site.com/sitev2/player.php?reciter=".urlencode($row['Sng'])."&cat=".urlencode($row['Cat'])."&ftype=".urlencode($row['FileType'])."&id=".urlencode($row['Id'])."&year=".urlencode($row['Year'])."&file=".urlencode($row['Link']).".".urlencode($row['FileFormat'])."' onClick=\"return openWin(this.href,200,100)\"> Play</a> <b style='display:none;'>-</b>"; } //mp3 player code closed else { echo " | Play <img src='images/player.gif' alt='' />"; } //share button echo "| <b style='display:none;'>-</b>"; echo "<!-- AddThis Button BEGIN --> <script type=\"text/javascript\">var addthis_pub = \"metheuser\"; addthis_brand = 'Site.com';</script> <a href=\"http://www.addthis.com/bookmark.php\" onmouseover=\"return addthis_open(this, '', '".$file2."', 'Site.com - ".$row['Topic'].".".$row['FileFormat']."')\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\">Share</a><script type=\"text/javascript\" src=\"http://s7.addthis.com/js/152/addthis_widget.js\"></script> <!-- AddThis Button END -->"; echo ("</div>"); echo ("</div>"); } $reciter = urlencode($reciter); //makes browser friendly //prev. page: ** LINK PATH** $prev_page = $page - 1; //css style for next,prev, links echo "<div class='mpages2'>"; if($prev_page >= 1) { if ($cat =='nohay'){ echo("<b><<</b> <a href='nohay.php?reciter=$reciter&limit=$limit&page=$prev_page'><b>Prev</b></a>"); } else { echo("<b><<</b> <a href='majlis.php?reciter=$reciter&limit=$limit&page=$prev_page'><b>Prev</b></a>"); } } //Display middle pages: ** LINK PATH** for($a = 1; $a <= $total_pages; $a++) { if($a == $page) { echo("<b> $a</b> | "); //no link } else { if ($cat =='nohay'){ echo(" <a href='nohay.php?reciter=$reciter&limit=$limit&page=$a'> $a </a> | "); } else { echo(" <a href='majlis.php?reciter=$reciter&limit=$limit&page=$a'> $a </a> | "); } } } //next page: ** LINK PATH** $next_page = $page + 1; if($next_page <= $total_pages) { if ($cat =='nohay'){ echo("<a href='nohay.php?reciter=$reciter&limit=$limit&page=$next_page'><b>Next</b></a> > >"); } else { echo("<a href='majlis.php?reciter=$reciter&limit=$limit&page=$next_page'><b>Next</b></a> > >"); } } echo "</div>"; //mpages2 div close //all done ############################################################################## } else { echo "<B><h1>You do not have permision to view this page. Code: 001</b></h1>"; } //close !isset perimeter $buffer = ob_get_contents(); //write to file cache $cachefile = "/sitev2/nohay.html"; // open the cache file "cache/home.html" for writing $fp = fopen($cachefile, 'w+'); // save the contents of output buffer to the file fwrite($fp, $buffer); // close the file fclose($fp); // Send the output to the browser ob_end_flush(); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2009 Share Posted March 1, 2009 Turn error reporting and dsiplay errors on and tell us if your getting an error. Quote Link to comment Share on other sites More sharing options...
zeeshan_haider000 Posted March 1, 2009 Author Share Posted March 1, 2009 Turn error reporting and dsiplay errors on and tell us if your getting an error. well that's what i am getting after turning error_reporting(E_ALL) on ; Warning: fopen(/sitev2/nohay.html) [function.fopen]: failed to open stream: No such file or directory in /homepages/46/d272861742/htdocs/site.com/sitev2/includes/functions.php on line 277 Warning: fwrite(): supplied argument is not a valid stream resource in /homepages/46/d272861742/htdocs/site.com/sitev2/includes/functions.php on line 279 Warning: fclose(): supplied argument is not a valid stream resource in /homepages/46/d272861742/htdocs/site.com/sitev2/includes/functions.php on line 281 Quote Link to comment Share on other sites More sharing options...
RussellReal Posted March 1, 2009 Share Posted March 1, 2009 what that is saying is that the file doesn't exist.. its trying to open the file from the base directory of your server.. not the base directory of the website.. try removing the first / in the filename.. you're looking for /sitev2/filename.html instead of /var/www/htdocs/sitev2/filename.html also its good to add, that fopen does not create a directory.. it may attempt to create a file depending on the mode you opened the file with (second parameter of fopen()). so since you're looking INSIDE of a DIRECTORY which doesn't exist.. the file isn't being created since the directory doesn't exist, therefore your php throws the error you're encountering Quote Link to comment Share on other sites More sharing options...
zeeshan_haider000 Posted March 2, 2009 Author Share Posted March 2, 2009 what that is saying is that the file doesn't exist.. its trying to open the file from the base directory of your server.. not the base directory of the website.. try removing the first / in the filename.. you're looking for /sitev2/filename.html instead of /var/www/htdocs/sitev2/filename.html also its good to add, that fopen does not create a directory.. it may attempt to create a file depending on the mode you opened the file with (second parameter of fopen()). so since you're looking INSIDE of a DIRECTORY which doesn't exist.. the file isn't being created since the directory doesn't exist, therefore your php throws the error you're encountering Well i already tried but no success.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.