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
https://forums.phpfreaks.com/topic/275137-changing-directory-with-php/
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

Archived

This topic is now archived and is closed to further replies.

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