开发者

File open causes timeout when php script is called by ajax with jquery

I'm writing code for an imageboard and my users are going to be able to post textfiles which will loa开发者_C百科d as pages in a css layer. I have a simple php script which takes a filename and some parameters(for start of line and lines per page) through GET, opens the file passed, and displays a section of that file as html:

http://pastebay.com/115710

I can confirm that this script works by calling it in a browser and setting the get string in the url.

I'm calling this script by AJAX using jQuery, binding a function to any links to textfiles in the page so that, when those links are clicked on, a layer opens up and (what I want to happen is) the html returned by the php file is dumped into that layer:

http://pastebay.com/115711

When I use the same AJAX call using the textfile itself the call is successful and I can load the contents of the textfile into the layer.

When I call the php file by AJAX, I get the following response when the php file never opens the textfile passed:

Blockquote Warning: file(http://localhost/kusabax/lit/src/nrd.txt) [function.file]: 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. in C:\xampp\xampplite\htdocs\kusabax\textview.php on line 6 Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\xampplite\htdocs\kusabax\textview.php on line 6

whatever the problem is, it's with trying to open the textfile itself - if I use fopen() or file() the result is the same, and without that line the script runs properly (except without, obviously, any useful results.)

I should also mention that I tried writing an iframe into the #prevwin layer and having the php script load into the iframe, and just writing the get attributes into the src string (not even using AJAX at all) - but I still got the same timeout.


I think I solved it.

Having the filename sent to the php script as an absolute url was the problem. I edited the javascript to change the url string to a relative url by splitting the href string and taking the current folder and filename and building a new url:

s = this.href;
a = s.split("/");
board = a[4];
src = a[a.length-1];
relhref="./"+board+"/src/"+src; 

and then passing relhref to the AJAX function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜