Jump to content

topcoder1

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by topcoder1

  1. I'm trying to use fopen another url, it doesn't work on localhost, however it works on other domains(such as google.com). The localhost url is valid. I have tried both fopen and file_get_contents. the php page simply hangs and says: PHP Warning: fopen(http://localhost/) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.\r\n in D:\\Program Files\\Apache Group\\Apache2\\htdocs\\myapp\\callurl.php on line 3 [Thu Apr 30 14:43:22 2009] [error] [client 127.0.0.1] PHP Fatal error: Maximum execution time of 30 seconds exceeded callurl.php: <?php //$content = file_get_contents("http://localhost/myapp/test.php"); $handle = fopen("http://localhost/", "r"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); echo($contents); ?>
  2. given a path, I want to check to see if a directory exists, then create one if it doesn't. dir(path) gives an error: [function.dir]: failed to open dir: Invalid argument . Are there functions allow me to do all those? thanks
  3. thanks, but even this doesn't work. Parse error: syntax error, unexpected T_OBJECT_OPERATOR I have to say: <?php class Test { public function oops() { echo 'oops."; } } $t=new Test(); $t->oops(); ?> I am using php4 though. Is there a way to not to create a temporary reference before calling the class member function? I mean is there a way to say invoke oops function on new Test() directly?
  4. <?php class Test{ function oops(){ echo("oops"); } } new Test().oops(); ?> error: Call to undefined function: oops() any idea? thanks
  5. I know there are two ways to pass arguments to an included page. 1. declare variable in the main page, and the included page will have access to this variable by default scope. in main.php $test="hi"; <?php include("include1.php");?> 2. pass the argument from get in main.php <?php include("include1.php?test=hi");?> the second way doesn't pollute the namespace but is limited to pass simple arguments(not arbitrary objects). Is there any other way?
  6. I have the following setup: Main.php includes A.php and B.php in A.php I make an ajax call to C.php which modifies data X. Now I reload B.php, can I get data X in B.php? I don't want to pass information to B from client side to reconstruct X. thanks!
  7. solution according to hbertini at sapo dot pt 13-Mar-2005 03:29 workaround when using session variables in a .php file referred by a frame (.html, or other file type) at a different server than the one serving the .php: Under these conditions IE6 or later silently refuses the session cookie that is attempted to create (either implicitly or explicitly by invoquing session_start()). As a consequence, your session variable will return an empty value. According to MS kb, the workaround is to add a header that says your remote .php page will not abuse from the fact that permission has been granted. Place this header on the .php file that will create/update the session variables you want: <?php header('P3P: CP="CAO PSA OUR"'); ?> Regards, Hugo http://us.php.net/function.session-start
  8. yes I am. Here's the complete code: index.php session_start(); $_SESSION['mydata']=$_POST['mydata']; // ok session_write_close(); //ensures that I dont lock the session for too long another php page I invoke later session_start(); error_log(print_r($_SESSION,1)); //nothing in the session array! also the html file that has the iframe is hosted by a different domain than the phps. They are both hosted on the same machine however. The problem only occurs on IE.
  9. I have a php app running inside an iframe. I pass a piece of info to this iframe through http parameters, php gets it and then set it in the session. However, the session data is lost when I read it from another php page within the same php application. index.php which resides in an iframe session_start(); $_SESSION['mydata']=$_POST['mydata']; // ok another.page that I later invoke error_log(print_r($_SESSION,1)); //nothing! this weirdness only happens on IE. and if I refresh the iframe again, the session data will be available. any idea? thanks
  10. no, that's the only configuration for gzip.
  11. I want to config gzip on apache server so that it compress everything except streaming files and images. I did AddOutputFilterByType DEFLATE text/plain text/javascript text/html. But it seems that certain request for file/image data gets gzipped as well. for example client sends a request http://myhost/file_streamer.php?id=101, my file_streamer.php respond with: function stream_file($filename, $file, $file_len=null){ header("Content-Disposition: attachment; filename=\"".$filename."\""); header("Content-Type: application/octet-stream");//octet-stream application/octet-stream if($file_len!=null)header("Content-Length: ".$file_len); header("Pragma: no-cache"); header("Expires: 0"); print $file; exit(); } I dont want this response content to be gzipped, how do I filter it properly? thanks
  12. thanks but if I create a config.php that sets my app file root, then I need to include that config.php as well... this problem becomes circular.. might as well put everything under the app root... there has to be a simple solution right? I searched for a while and not able to find one...
  13. I have 3 files Index.php, x.php and login/Login.php in Login.php <?php require_once "../x.php"; ?> Index.php <?php require_once "login\Login.php"; ?> when executing Index.php error is Failed opening required '../x.php' I can of course say <?php require_once "x.php" ?> in Login.php, then Index.php would load fine.. However if I load login\Login.php independently, x.php would not be found. So what should I do?
  14. Thanks! for 2) I found out that there's a bug in my mysql community server version 5.02 http://bugs.mysql.com/bug.php?id=14955 so I'm stuck with 1MB max file insert blob unless I upgrade mysql server.... which I am hesitant to do. so much for trying to store files in database...
  15. question 1: there's a limit on how much you can upload and insert into a blob field in phpMyAdmin: 8192 kb, this is certainly not the blob limit, a quick search on google says it's a process stack size limit. what is this 8192 kb limit? is it simply the limit on file size that can be uploaded into phpMyAdmin? what's the reason behind it? question 2: another related issue is whenever I tries to insert a big file(for example, >1MB) into a longblob field using mysql_query, mysql dies and says "MySQL server has gone away"), smaller files are ok.. what's up with that? thanks
  16. in a typical php file that accepts parameters I do something like this: $a=null; $b=null; $c=null; //100 more lines like above if(isset($_POST['a'])) $a=$_POST['a']; if(isset($_POST['b'])) $a=$_POST['b']; if(isset($_POST['c'])) $a=$_POST['c']; //100 more lines like above //now business logic if($a !=null & b!=null){ } else if($a!=null && c!=null){ } else if($a==null && b==null & c!=null){ } now I can do this and saves lots of repeative code. $array=array("a","b", "c",...); // 1 line instead of 200 lines... foreach($array AS $el){ if(isset($_POST[$el]) $el = $_POST[$el]; }else{ $el = null; } } //then my business logic as usual if($a !=null & b!=null){ } else if($a!=null && c!=null){ } else if($a==null && b==null & c!=null){ } I am no php proficient. so Maybe there's other easy solution someone can point out. thanks
  17. Ok I was a little quick on making the conclusion about php tag. The root of all evil is the empty lines before the php tag starts the blank lines before <?php are being sent as part of the server response to the client. In my case, my include class had blank lines in the beginning and these lines are sent back to the client as part of the download, hence caused the problem. I am still vague as to why that caused the download problem since those blank lines are sent before the http headers and the file data itself, but I'm beat and need some sleep. my working test code follows, if I add any blank lines before any of those php starting tags, it will break. test.php <?php require_once "Streamer.php";?> <?php $a=new Streamer(); $a->stream_file("test.jpg", "c://temp//output//test.jpg"); ?> Streamer.php <?php class Streamer{ function stream_file($filename, $file, $file_len=null){ header("Content-Disposition: inline; filename=\"".$filename."\""); header("Content-Type: application/force-download");//octet-stream if($file_len!=null)header("Content-Length: ".$file_len); header("Pragma: no-cache"); header("Expires: 0"); readfile($file); exit(); } } ?>
  18. OK I FINALLY FIGURED IT OUT. You guys would not believe what's the cause of the problem.. It's not the db, not even the streaming function... I had a funny feeling something as obscure as this is the problem. case 1: it works <?php require_once "item.php"; $item=new Item(); $item->test_stream_file(); //stream a file over http ?> case 2: it corrupts the file!! <?php require_once "item.php"; ?> <?php $item=new Item(); $item->test_stream_file(); ?> It seems that when closing and restarting the php tag something is send over http that messed the file download up. Who would have thought!!! thanks all
  19. I am just trying out this way to see how it will work. I know there's a whole debate of db vs flat file going on... Anyway debugging to this point it seems that it's unrelated to db, the server reads from a flat file and then stream it to client, but the file is corrupt after DL... maybe I'm just insane here...
  20. Ok I tried outputting to a temp file, then readfile(), still after I download the file, i can't open it. But I view the temp file on server and it's fine. the temp file and the file I DL are the same size. What is going on?? I am using FF. something's very bizzare here... $handle = fopen("c://temp//output//".$file_name, 'w'); fwrite($handle, $file); fclose($handle); /* $handle=fopen("c://temp//output//".$file_name, 'rb'); error_log("fread ".fread($handle, filesize("c://temp//output//".$file_name))); fclose($handle); */ $this->stream_file($file_name, $file_len, $file); } } function stream_file($filename, $file_len, $file){ header("Content-Disposition: inline; filename=\"".$filename."\""); header("Content-Type: application/octet-stream");// // header("Content-Length: ".$file_len); header("Pragma: no-cache"); header("Expires: 0"); //print base64_encode($file); error_log("file name is ".$filename); error_log("file read ".readfile("c://temp//output//".$filename)); exit(); }
  21. thanks for the help. I tried using header application/octet-stream and base64_encode since convert_uuencode is a php5 function and I use php4. still doesn't help. Image gets downloaded then can't be opened. function stream_file($filename, $file_len, $file){ header("Content-Disposition: inline; filename=\"".$filename."\""); header("Content-Type: application/octet-stream");// // header("Content-Length: ".$file_len); header("Pragma: no-cache"); header("Expires: 0"); print base64_encode($file); exit(); }
  22. I am streaming some files from the database and serve it over http, for text files and even pdf files it works, but for image files and xls files the files seem to be corrupted. For testing purpose, after I grab the file from the blob field in mysql db, I write it to a file on the server which looks good by manual inspection. However when the user downloads and opens the file it's corrupted. For xls, there are bunch of binary codes scattered around with texts. For image file it simply can't be viewed. What's wrong?? function html_item_file($item_id){ $this->init_db(); $query="..."; if($res=mysql_query($query)){ $item=mysql_fetch_assoc($res); $file=$item['file_content']; $file_name=html_entity_decode($item['item']); $file_len=$item['file_len']; error_log("file is ".$file_name.", ".$file_len); error_log("q is ".$query); //extract raw and save to file, this result file looks good /* $handle = fopen("c://temp//output//".$file_name, 'w'); fwrite($handle, $file); fclose($handle); */ $this->stream_file($file_name, $file_len, $file); } } function stream_file($filename, $file_len, $file){ header("Content-Disposition: inline; filename=\"".$filename."\""); header("Content-Type: image/png");//application/octet-stream // header("Content-Length: ".$file_len); header("Pragma: no-cache"); header("Expires: 0"); echo $file; exit(); }
  23. It's mainly for reducing the lines of code I have to write, for example if I have 100 params like this that I have to assign individiually, it's roughly 100 lines of code. Now I can just do the above and have the same effect. it's very useful I think.
  24. thanks a lot! that's what I want!
  25. I mean is there a way to do something like this: $array=array("param1","param2"...); foreach($el in $array){ if(isset($_POST[$el]) createVariableAndAssignValueTo($el, $_POST[$el]); else createVariableAndAssignValueto($el,null); } //now I have all my params! echo($param1); echo($param2); does that make sense? thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.