PHP - Readfile() Causing Browser To Hang..i Think..
I have an FLV player and I am using a php file to read an FLV that is above webroot. It reads the FLV just fine, however, during its cache process or while it is still downloading, if I click on the home button (home button of the current site), the server does not respond until the FLV has been fully cached.
Now this is only occuring in firefox, chrome and IE. In safari it works fine. Who know, maybe it is a header issue. Here is my script that I pass to my FLV player <?php include("connect.php"); if ($_SESSION['loggedIn'] == true) { $id = $_GET['id']; $query = mysql_query("SELECT video FROM reviews WHERE id = '$id'"); $row = mysql_fetch_array($query); $filename = "../../../armsmedia/videos/".$row['video']; header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename='.basename( $filename ) ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filename ) ); ob_clean(); flush(); readfile( $filename ); exit; } ?> Similar TutorialsHi all, Yesterday I transferred my hosting to a new provider. Everything is up and running apart from the following message I get on my index page Warning: readfile() [function.readfile]: Filename cannot be empty in /home/XXXX/public_html/imgsize.php on line 64 . This error is only on the index page. When I look at line 64 it states the following: readfile ($img); I have tried replacing the imgsize.php file but that still does not work. And on my old hosting this error does not occur. If you could please help, I would appericate it. Cheers Steve I recently migrated from Windows XP to Windows 7, and a PHP package I depend on (mPDF, see http://www.mpdf1.com/mpdf) stopped working. When I call one of its necessary functions, it hangs. I investigated further and found that the crash was happening in a call to file_get_contents, given one parameter, a URL that points to a CSS file. I found that the file_get_contents and file functions both crash when given a URL. Both work normally when given a pathname on the local file system. As I understand it, these functions are supposed to accept a URL if the INI directive allow_url_fopen is enabled. I checked by calling ini_get; it is. In any case, the php.net description of fopen says that if that directive is disabled, "PHP will emit a warning and the fopen call will fail" -- not just hang! It appears as if there is a glaring bug in one of PHP's core functions. I'm very skeptical that that is really the problem, but I don't know what else to suspect. Any ideas? My configuration is Windows 7 Professional with SP1; Apache 2.2.17; PHP 5.2.17. For reference, here is the script I used to investigate this problem. I stepped through it with a debugger, so I didn't bother displaying results. As shown, the script works. When I comment out the second assignment to $path it should produce identical results; instead it hangs. Code: [Select] <?php $isopen = ini_get('allow_url_fopen'); $path = "http://localhost/pdf/cert.css"; $path = "D:/htdocs/pdf/cert.css"; $contents = file($path); $contents = @file($path); $contents = file_get_contents($path); $contents = @file_get_contents($path); ?> Hey, having some troblems using the readfile function.. I have the following code. I want to download the file "blabla.gif", but the file is in a certain directory (let's say: "/ExampleFile/Files/" . How do I set the path to "/ExampleFile/Files/" ? $file ='blabla.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } Thanks, Ruben So to stop third-party traffic on certain media files my site does, I did a download.php type script that just took in the media id, and found the filename and did a readfile on it for the user. The problem is that when you start doing massive amounts of traffic with it, I think the readfile stream is taking up a lot of cpu. Is there any alternative to readfile that creates a direct link between the user and the file, instead of it having to go through the php? I'm afraid that this is something I need to do on the server end, and not in PHP, but I figured I'd ask. Hi guys Im new here. Ive got a small problem. I have a simple uploading script, had problems with that too but its working fine now to a certain extent. When I set a download link for the files that have been uploaded and click to download, it downloads but I get the following errors when I open the file, its a .txt file. But it seems to happen on all files also, it allows me to download .png, .php, .jpg bout it wont actually open them once they are downloaded (Ive change the domain to an example, its not my actual domain within the warnings below): The following warnings occurred: Warning [2] filesize() [function.filesize]: stat failed for http://mydomain/expiry_files/downloads/text.txt" - Line: 69 - File: expiry_download.php PHP 5.2.17 (Linux) Warning [2] readfile(http://mydomain/expiry_files/downloads/text.txt") [function.readfile]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found - Line: 70 - File: expiry_download.php PHP 5.2.17 (Linux) Here my download file, most of it (Ive also attached an image of the text file after I downloaded it and opened it, below): if (isset($_GET['id'])){ $file_id = (int)$_GET['id']; $file = $db->query("SELECT * FROM ".TABLE_PREFIX."expiredownloads WHERE `id` = {$file_id}"); $row = $db->fetch_array($file); if ($row['expire_end'] < time()){ //// Do nothing Yet }else{ $link = ''.$mybb->settings['bburl'].'/expiry_files/downloads/'.$row['expire_file'].'"'; $filename = $row['expire_file']; header('Content-type: application/octetstream'); header('Content-type: application/octet-stream'); header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"$filename\""); header('Content-Length:'.filesize($link)); readfile($link); } } Hope you guys can spot a problem, If you require anymore information, just shout. Thanks in advance. i'm trying to import my print-on-demand shop without using frames. pg i'm importing - http://byuhonorcode.spreadshirt.com/ my site - http://byuhonorcode.com/index2.php Code: [Select] <?php $pg=file_get_contents('http://byuhonorcode.spreadshirt.com/'); echo $pg; ?> the page appears, but the these features no longer function: - switchColor javascript changes shirt color onClick of swatch (located @ http://cache.spreadshirt.com/Public/Shop/Js-packaged/shop_de23789016327809b00d204c6add79ba.js) - the arrows that change the color swatches - the size option box any ideas? Thanks! I wrote a small application to force downloads of various large video files using readfile. This worked fine. However, the users have changed hosts and now it doesn't work. Small files are fine, but large files will cut off before finishing. Test file is 114MB, but it is always cut off at exactly 67.2MB or 51.4MB depending on a couple criteria. I've stripped the application down to the key part that's not working and run it on a test page the just immediately goes the file - no logins or any of that shenanigans and htaccess blocking either: $file = some/file/on/the/server.wmv; //114MB hea der('Content-Description: File Transfer'); hea der("Content-Type: application/octet-stream"); hea der("Content-Disposition: attachment; filename=" .basename($file)); hea der("Content-Transfer-Encoding: binary"); hea der('Expires: 0'); hea der('Cache-Control: must-revalidate, post-check=0, pre-check=0'); hea der('Pragma: public'); hea der('Accept-Ranges: bytes'); hea der("Content-Length: ".filesize($file)); ob_clean(); flush(); @readfile($file); (gaps in the header words are to prevent forum breakage) I've tried the following variations: transfer encoding - chunked (this results in getting a 51.4 MB download rather than 67.2) content-type application/force-download tried the default force-download code from the php.net manual tried the chunking function variations on php.net readfile page tried without accept ranges originally (only spotted that on this site) set_time_limt to one hour set max memory to 300MB (phpinfo has shown these changes did get accepted) used htacess to disable gzip and deflate (this results in getting a 51.4 MB download rather than 67.2) (SetEnv no-gzip dont-vary or RewriteEngine On RewriteRule . - [E=no-gzip:1] or RemoveOutputFilter DEFLATE html txt xml css js php wmv) None of these have solved the issue. The code worked fine on the old site, works fine on my site, and works fine on my test server. Direct downloads from the broken site also work fine, just not readfile downloads. The filesize is reading correctly if I echo just that, and it reads properly on the progress bar when downloading through readfile. The hosting company are blaming my coding. The htaccess is the bit I'm least sure of and I find it hard to get solid info on this part on the web. Is there anything wrong with my code that could be causing this? Am I missing something? What could be causing the problem? Many Thanks I'm trying to use the readfile() function to read a html page which has a video embedded (.swf file). When I call the function, it seems like it just loads the html file but without the dependent files (css,js, etc) When I call it directly it loads just fine. Created a hyperlink 'openvideo.php?id=video' that calls this function below: if($_REQUEST['id'] == 'video') { readfile('/usr/home/site.com/htdocs/content/videofolder/video.html'); } else { echo 'nada'; } Any help is appreciated. In a PHP file [php_one.php], I wrote some PHP code that contained a form. I used ECHO to write the HTML inside of the PHP tags. On another PHP page [php_two.php], I wanted to show the code that was used to create the first page [php_one.php]. My first effort provided an interesting result, since the PHP code was readable. However, all HTML code was visible in its executed form. There was an actual input field and a submit button (not the code used to produce them) in the context of my coding. I have tried using:
file_get_contents("FILE") All results were similar and carried the same problem. How can I view code so that even the HTML is visible as code?
An image is saved in the root directory. $file = '../image.jpg'; // IN ROOT DIRECTORY $type = 'image/jpeg'; header('Content-Type:'.$type); header('Content-Length: ' . filesize($file)); readfile($file);
The image then gets embedded into an html page and displayed like this:
QUESTION: in the event of an error, how do I dipslay the readfile error on the customer's html page? Make sense? No. I probably have to rewrite my question 😃 Edited Monday at 01:07 AM by ChenXiuAn image is secured in the root directory, to be displayed to customer in html document.
This image can be displayed as a link to a php readfile page Which is better? Why and why not? Thank you. Edited yesterday at 01:15 PM by ChenXiuWhich is better? Why and why not? An image is secured in the root directory, to be displayed to customer in html document.
This image can be displayed as a link to a php readfile page Thank you. I am wanting HTML to render within a table and sourcing the data from another file. In an attempt to do this, I tried: Code: [Select] <TABLE class="main"> <TR> <TD> <?php readfile('./1/index.html'); ?> </TD> </TR> </TABLE> This does not work and I am wondering if anyone knows how it can be done - or even if it can be done?
Circumstance:
Question:
This works by having the actual image name stored in a hidden session variable, using the following lines of code on my readfile page "label.php" like this: Since I do not want customers to be allowed to ever see the image again after logging out, is it okay to rely on a hidden session variable for the filename as I described above? (Potential hackers will be less tempted to "try different image names and numbers" like "id1.png, id2.png, id3.png" because they will have no idea if the image will be a gif, jpeg, or png, nor have any idea of a numbering sequence.) Thank you!!
The code below is working in relation to what I expect it to do however it is allow causing this error on top of the form everytime... Notice: Undefined index: submit in C:\wamp\www\protek\register.php on line 130 Notice: Undefined index: fullname in C:\wamp\www\protek\register.php on line 133 Notice: Undefined index: email in C:\wamp\www\protek\register.php on line 134 Notice: Undefined index: username in C:\wamp\www\protek\register.php on line 135 Notice: Undefined index: password in C:\wamp\www\protek\register.php on line 137 Notice: Undefined index: password2 in C:\wamp\www\protek\register.php on line 138 The full code being used is > <?php //check for submit $submit =$_POST['submit']; //gather POST variable $fullname =strip_tags($_POST['fullname']); $email =strip_tags($_POST['email']); $username =strip_tags($_POST['username']); $password =strip_tags($_POST['password']); $password2 =strip_tags($_POST['password2']); if ($submit) { //check that fields were filled in if ($fullname&&$email&&$username&&$password&&$password2) { //now we can encrypt our password to md5 $password = md5($password); $password2 = md5($password2); //were done seeting md5 //check to see if our two password fields match if ($password==$password2) { //check to see if the password is greateer than 25 but less than 6 if (strlen($password)>25||strlen($password)<6) { //if it is then echo "<font color='red'>Your password must be between 6-25 characters</font>"; } //otherwise register the user else { echo "Success"; } } //otherwise if passwords don't match else echo "<font color='red'>The passwords you entered do not match</font>"; //end of checking password } else echo "<font color='red'>Please enter all fields!</font>"; } //end check for submit ?> Hi There, I have an application that uses a Flash front end. The user fills out a card. The variables of that card are stored in an SQL Database and the recipient gets an email with a unique url to retrieve the card. The problem I am faced with ... is that if the user hits their ENTER key while typing their message to create line breaks.. the line breaks are causing the SWFOBJECT Flash Embed to break. The SWFOBJECT embed code looks like this Quote var flashvars = { yname: "<?php print "$yname";?>", yemail: "<?php print "$yemail";?>", fname: "<?php print "$fname";?>", femail: "<?php print "$femail";?>", greeting: "<?php print "$greeting";?>", message: "<?php print "$message";?>", fullname:"<?php print "$fullname";?>" }; The results look like this when data has been filled out Quote <script type="text/javascript"> var params = { quality: "high", //scale: "ExactFit", wmode: "transparent", menu: "false", allowfullscreen: "true", allowscriptaccess: "always", bgcolor: "#014872" }; var flashvars = { yname: "Jonathon", yemail: "name@email.com", fname: "TEST", femail: "jname@email.com", greeting: "TESTING", message: "Test Test Test", fullname:"" }; You can see the line breaks whe Test Test Test Was typed. Any ideas how to fix this ? So I have an webapp which has a built in proxy checker. However because I didn't write the code I am kind of confused on whats going on. I have a small amount of knowledge on php been looking all over the net to find a solution. So this file called (proxy_check.php) keeps causing my index.php to show the 404 designed page. The file is required in the index.php file. I believe its something to do with the $reponse variable. Please help <?php # Visitor proxy check snippet $v_ip = $_SERVER['REMOTE_ADDR']; $arContext['http']['timeout'] = 10; $context = stream_context_create($arContext); $response = file_get_contents('http://www.shroomery.org/ythan/proxycheck.php?ip='.$v_ip, 0, $context); if ('Y' === $response) { echo "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'> <head> <title> The page you were looking for doesn't exist (THIS BUG)</title> <style type='text/css'> body { background-color: #efefef; color: #333; font-family: Georgia,Palatino,'Book Antiqua',serif;padding:0;margin:0;text-align:center; } p {font-style:italic;} div.dialog { width: 490px; margin: 4em auto 0 auto; } img { border:none; } </style> </head> <body> <div class='dialog'> <a><img src='assets/img/404.png'></a> <p>It looks like that page you were looking has been mislaid, sorry.</p> </div> </body> </html>"; die(); }
I am having problems understanding how to sanitize my form data so it is safe to INSERT. If I use this code... Quote $trimmed = array_map('trim', $_POST); $body = mysqli_real_escape_string($dbc, $trimmed['body']); And I enter into my form... Quote O'Reilly's book Then I see this in phpMyAdmin... Quote O\'Reilly\'s book --------- If I use this code... Quote $trimmed = array_map('trim', $_POST); $body = $trimmed['body']; And I enter into my form... Quote O'Reilly's book Then I see this in phpMyAdmin... Quote O'Reilly's book Why the strange behavior?? Debbie Have a strange problem on a new server that we've migrated to. I use class.phpmailer extensively with no problems but since moving to the new one, i notice that emails sent to ids on the same domain as the sender just dont go thru . i cannot figure out why this could be happening. What could i do to resolve this problem please? Thanks: Swati. OLD SERVER : PHP 2.6.4 , MYSQL - 4.1.12 NEW SERVER PHP 3.2.4 , MYSQL 5.1.50 My code snippet <? if($_POST['submit']){ $dec = $_POST["dec"]; require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsMail(); $mail->From = "form@exam.com"; $mail->FromName = "exam"; if ($dec == "on"){ $mail->AddAddress("dec@exam.com"); // doesnt go thru $mail->AddAddress("dec@anyother.com"); // goes thru // add it } } ?> Hey, I'm writing an application that tracks attendance. There are multiple events ('events' table), in which members that are present will be found. (When an event file is uploaded, it has all members that attended the event, and adds the event entry in 'events', as well as adding each member to the 'attendance' table, with event_id(eid) and the 'did_attend' value as '1'. When the event is edited, it needs to find the other members that AREN'T in the events table, and add them to the 'attendance' table. When I use this code, it apparently keeps adding the same members. Will a LIMIT 1 stop this? I has about 65,000+ entries added before I stopped the execution of the script. Thanks! Code: [Select] $sql2 = mysql_query("SELECT * FROM members WHERE status=1 ORDER BY mid ASC"); while($row = mysql_fetch_assoc($sql2)){ $sql3 = mysql_query("SELECT * FROM attendance WHERE event='$eid' ORDER BY member ASC"); while($row2 = mysql_fetch_assoc($sql3)){ if($row2[mid] == $row[mid]){ // if the member is in the attendance db, skip }else{ //if member is not in attendance, write zero--- causing multiple entries (50,000+) $qry = mysql_query("INSERT INTO attendance (member,event,did_attend) VALUES ('$row[mid]','$eid','0')"); if(!$qry){ die("SQL: ".mysql_error()); }else{ $msg = "<br />Member ".$row[mid]." marked as absent."; } } } } |