Closed Thread Icon

Topic awaiting preservation: Illegal seek? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12640" title="Pages that link to Topic awaiting preservation: Illegal seek? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Illegal seek? <span class="small">(Page 1 of 1)</span>\

 
synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 03-08-2003 23:28
code:
<?php

$i = 0;
$path = "http://borg.cs.dal.ca/";
$users = `ls ../../`;
$buffer = split("\n" , $users);

while ($i < count($buffer)) {
if ($fp = fopen($path . "~" . $buffer[$i++] . "/", "r"))
echo "<a href=\"". $path . "~" . $buffer[$i] . "\">". $buffer[$i] . "<br />";
fclose($fp);
}

?>


http://borg.cs.dal.ca/~dion/act_dirs.php
Be prepared to hit the "Stop" button in your browser.

Can anyone help me here?

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-09-2003 02:13

Could it have anything to do with a .htaccess settings or permissions on the directories?

I grabbed one of the urls from the error messages and tried to open them in the browser and got a 403 Forbidden.

-Butcher-

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-09-2003 04:31

synax: Illegal seek errors seem pretty simple things:

quote:
You aren't allowed to seek on a pipe. Socket calls can also return this.



and:

quote:
An illegal seek error is a very common condition and often not really an error. The output of your command in backticks is read through a pipe, and very often a file descriptor is tested to see if it is a pipe by performing a seek and looking for an illegal seek error, since pipes are not seekable. It is therefore likely that the series of system calls performed by the backticks include a seek on the pipe, causing the ESPIPE value in errno.



but as its late I'm not actually sure what it is telling you

As Marty has suggested it seems to be a permissions/sockets kind of thing although its possible that just turning off the error handling fixes things as suggested in the manual:
www.php.net/fopen

What exactly are your trying to do? I'm looking at your code and you seem to be trying to split this:

quote:
$users = `ls ../../`;



using a newline but there aren't any newlines in that string which is a little confusing - this means there is no buffer[$i++] which would rather screw things up.

___________________
Emps

FAQs: Emperor

synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 03-09-2003 06:17

Allow me to break it down.

The script I am making searches my school's server for valid websites. "ls ../../" is a UNIX command to list all the files two directories up from my public_html directory. All the students in Computer Science have webspace on the same server in a subdirectory labelled by their username. What I'm trying to do is grab a listing off all the names, try to open the index of their directory (which will either work or return false in the case of a 403) and if it will open, print a link to it.

I've tried fopen() in both cases, where I know there'll be a 403 (because there's no public_html access) and I where I know there is public_html access. It work in both cases. But now something doesn't want to work...

The only difference is before I just called fopen() directly, like fopen("http://borg.cs.dal.ca/~dion/", "r") and that worked fine.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-09-2003 14:07

synax: Ahhhhhh right I see well the main problem is although this might be a Unix command:

quote:
$users = `ls ../../`;



PHP is just treating it as a text string. You need to actually execute the command and although I'm not sure if it is possible from where you are you want to look at functions like:

system()

I would recommend you make sure you actually are able to get a list of users before you try using fopen or you are going to end up in bother - I also suspect that the use of $buffer[$i++] will cuase you problems as it will always make the last fopen fail.

___________________
Emps

FAQs: Emperor

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 03-09-2003 16:41

How about

code:
function php_get_contents($dir_name) {

$dir_contents = dir($dir_name);

while ($dir_line=$dir_contents->read()){
if (( $dir_line!=".") AND ($dir_line!="..")){
// do some processing on $dir_line;
}
}
}


I didn't test it, but I did take it from another routine of mine to build a menu of thumbnails from the contents of a directory ... and that works ...

code:
<?
// php-functions.php
//
// FUNCTION php_get_filenames($dir_path)
// --------------------------------
// PARAMETERS - $dir_path - string - full path of the directory containing the thumbs
// RETURNS - array of strings - names of the thumbnails/images in the directory
// CALLED FROM - php_build_menu()
// ==============================================================================
//
// FUNCTION php_build_menu($dir_name)
// --------------------------------
// PARAMETERS - $dir_name - string - name of the directory containing the thumbs
// (n.b. only the last dir in the path is needed,
// (i.e. ./images/thumbs/classical - only classical needed
// RETURNS - no values returned
// PURPOSE - Creates and outputs the HTML required to make the menu box contents
// CALLED FROM - menu.php directly
// =============================================================================

function php_build_menu($dir_name) {
$base_path="/data/home/WWW-home/html/muralco";
$thumb_path="/images/thumb/".$dir_name."/";
$image_path="/images/big/".$dir_name;
$dir_contents = dir($base_path.$thumb_path);
while ($dir_line=$dir_contents->read()){
if (( $dir_line!=".") AND ($dir_line!="..")){
echo "<p class=centred>";
echo "<A HREF=javascript:loadImage('".$dir_name."','".$dir_line."')>";
echo "<img src=.".$thumb_path.$dir_line.">";
echo "</A></p>\n";
}
}
}

?>


The php dir command works like executing the ls ...



[This message has been edited by trib (edited 03-09-2003).]

synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 03-10-2003 00:34

No Emps, those aren't single quotes, they're backticks.

trib: I'll give your solution a go tomorrow when I have time to look into it more.

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 03-10-2003 07:10

I suggest you also look at the is_file() and is_dir() functions ...

code:
$got_em=array();

function php_get_websites() {

$dir_name="/absolute/path/to/homedirs/";
$dir_contents = dir($dir_name);
//
while ($dir_line=$dir_contents->read()){
//
// make sure you're looking in directories and not files
$full_dir=$dir_name.$dir_line;
if (( $full_dir!=".") AND ($full_dir!="..") AND ($is_dir($full_dir))){
//
// it's a directory so ...;
if (is_file($full_dir."/public_html/index.html")) {
//
// We found one with an index file etc. ... save it for later;
$got_em[$count++]="http://www.wherever.edu/~".$dir_line."/index.html";
}
}
}


Of course, if your web server permits other extensions as default startup files, then you need to make other arrangements. OTOH I already see that several of your co-students don't actually have valid index files in their dirs, even if their ~username actually works. You're in for a bit of fun sortig out the possibilities

I'm sure one of the real wizz programmers will improve on my crude offering above, but it ought to work (abeit mebbe a bit klunkily).

[This message has been edited by trib (edited 03-10-2003).]

synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 03-10-2003 16:26

Well what I'm trying to do is try and open each student's directory, and if I can't open it, I don't print it. I'm only interested in the directories that have public access. This is why I'm just trying to fopen() them all (which works). For some reason though, the problem is with my UNIX ls command. I'm going to try something different...

« BackwardsOnwards »

Show Forum Drop Down Menu