It is currently Sat Dec 04, 2021 7:57 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Opendir problem
PostPosted: Sun Jan 06, 2008 6:25 pm 
Newbie
Newbie

Joined: Mon Jul 16, 2007 7:37 pm
Posts: 14
i am making a web host beta for my website before i move it to my main domain, and need some help. on my file manager, i want to show a list of files from another directory. to see the error i am getting go here:

http://telviorhostingbeta.freehostia.co ... u=testuser

here is the code i am using. this is for a file manager:

<?php
if ($handle = opendir('/loggedin/editor/$hsitename')) {
echo "Directory handle: $handle\n";
echo "Files:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}

closedir($handle);
}
?>


-- HSITENAME is the user's url from my mysql database table
for example, if the HSITENAME was 'hello', the url would be HTTP://TELVIORHOSTINGBETA.FREEHOSTIA.CO ... OR/_HELLO/,
which is where the files i want to show are...

ask for more info if needed...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 9:14 pm 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
try this

Code:
<?php

if ($handle = opendir(getcwd() . '/loggedin/editor/'. $hsitename)) { // change 1 seperate the $hsitename and added getcwd() .  which tells the code its current directory.
echo "Directory handle: $handle\n";
echo "Files:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}

closedir($handle);
}
?>



I started making a Control Panel a while ago, but never get around to using it. I then lost the original in a system failure and my web space got closed down so i let that copy too. (that was just before i switched to freehostia)

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 10:43 pm 
Newbie
Newbie

Joined: Mon Jul 16, 2007 7:37 pm
Posts: 14
i see what you are saying, but that didn't work. here's how the page works...

you signup and it makes a mysql entry with 'siteName' being one of the fields. for example, if i sign up as 'Bob' and choose 'BobsSite' as my url, the actual url will be:

http://telviorhostingbeta.freehostia.co ... _BobsSite/

So... the way the dir is created is in the /loggedin/editor dir with a '_' before the url. the editor is in /loggedin/editor/tEdit/e5/advanced/

the editor dir (which contains the opendir problem) is in a deeper directory than the files being viewed. Try looking at the error now:

http://telviorhostingbeta.freehostia.co ... u=testuser

-----------------------------------------------------------

a deeper look at how the url is made:

-user signs up with the url 'GregsBlog'
-the form they used to submit that information is sent on to the $_POST of the PHP document that processes that:

(adduser.php)
<?php

$theurl1 = $_POST['chosen_url']; // 'GregsBlog'
$theurl = "_" . $theurl1; // '_GregsBlog'
$user = $_POST['submitted_username'];

(MYSQL CONNECT STUFF)

(MYSQL UPDATE (Updates the blank 'siteName' field for the user to $theurl))

header("Location: editor.php?user=$user");

?>

On the Editor page, it gets the MySQL value for 'siteName' from the user's entry (_GregsBlog). Then the problem:

the opendir command opens the folder 'http://telviorhostingbeta.freehostia.com/loggedin/editor/$theurl/'

^ $Theurl being the 'siteName' value for the user from the database.


if that doesn't help, make yourself an account called 'Tester' for example and see for yourself how it works. I'll delete it later. If that doesn't help, i can give you the username/password for my freehostia account and you can see the code from signup all the way through the editor and then i'll change the password. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 11:06 pm 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
ok i think ive got it now :)

Code:
<?php

if ($handle = opendir(getcwd() . '../../../../../_'. $hsitename)) {
echo "Directory handle: $handle\n";
echo "Files:\n";

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}

/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}

closedir($handle);
}
?>



see if that helps, if not i will create an account

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject: ...
PostPosted: Sun Jan 06, 2008 11:40 pm 
Newbie
Newbie

Joined: Mon Jul 16, 2007 7:37 pm
Posts: 14
it isn't working:

http://telviorhostingbeta.freehostia.co ... u=betauser

...maybe Opendir() isn't the function i should use. you could create an account and see if that makes a difference (i'll delete it later), but it seems like opendir is strictly for folders down from the editor. if you cant find a solution after creating an account, i will edit the site to have the editor be in a higher directory. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ]  Moderators: Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Hosting | Domains | Servers | Extras | Order | Support | Contacts | FreeHostia © 2011