Jump to content

changing directory with php


ksun

Recommended Posts

ok, so i'm kinda new to ftp with php, i'm having difficulties with getting contents of my public_html directory (i'm using a free web hosting service)

 

 when i'm using ftp_rawlist(); to retrieve public_html content, it returns an empty array.

<?php 

$ftpServer = "usetheforce.hostei.com"; 
$ftpUser = "*"; 
$ftpPass = "*";


$conn = @ftp_connect($ftpServer) 
or die("Couldn't connect to FTP server"); 

$login = @ftp_login($conn, $ftpUser, $ftpPass);

$workingDir = ftp_pwd($conn); 
echo "Files for directory: $workingDir<br><br>"; 

$fList = @ftp_nlist($conn, $workingDir); 

if(is_array($fList)) 
{ 
$newDir = $fList[4]; // public_html

if(ftp_chdir($conn, $newDir)) 
{ 
$fList1 = ftp_rawlist($conn,$newDir); 
echo ftp_chdir($conn, $newDir);
if(is_array($fList1)) 
{ 
echo "Files for directory: $newDir<br><br>"; 
echo sizeof($fList1); 
for($i = 0; $i < sizeof($fList1); $i++) 
{ 
echo $fList1[$i] . "<br>"; 
} 
} 
else 
{ 
echo "$newDir contains no files."; 
} 
} 
else 
{ 
echo "An error
 occured while changing to $newDir or $newDir is not a directory"; } 
} 
else 
{ 
echo "$workingDir contains no files."; 
}
?> 

i've kinda isolated the problem, when i use: echo chdir($conn, "public_html") , it says: Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to public_html:. if anyone could help that would be gr8

thanks

Link to comment
Share on other sites

i did print_r for the $flist(amount of files in the defult diirectory) and it said 5 items, i then did the amount of files in the directory i'm trying to get to(public html) and it ssyas there is no items in the array. ive tried to echo chdir($conn, "public_html"), but it says. Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to public_html: No such file or directory in /home/a3893538/public_html/test.php on line 25. but when i echo something like chdir($conn, "../"), it works fine.

ty

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.