flashwebhost
08-31-2006, 05:43 PM
Hi,
I want to make a PHP script that will upload files to FTP server with different folders.
The script should create folder, if folder is not exist in FTP server.
# change the directory
if (ftp_chdir($conn_id, $remote_folder)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory <BR>";
if (ftp_mkdir($conn_id, $remote_folder)) {
echo "successfully created $remote_folder <br>";
} else {
echo "There was a problem while creating $remote_folder <br>";
exit(0);
}
if (ftp_chdir($conn_id, $remote_folder)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "<BR>";
} else {
echo "Couldn't change directory <BR>";
exit(0);
}
}
This is the code i use. It will try change directory, if it fails, Try creating FOLDER, then try change again. Still it do not work, script will exit.
The problem with the script is, when folder is not present, it will show error message like
Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to kerala: No such file or directory in D:\sites\test.php on line 18
Couldn't change directory
successfully created kerala
Current directory is now: /kerala
Is there any way i can avoid this error in cause of FOLDER not present ?
Anyway to check presense of folder ?
Thanks,
Yujin
I want to make a PHP script that will upload files to FTP server with different folders.
The script should create folder, if folder is not exist in FTP server.
# change the directory
if (ftp_chdir($conn_id, $remote_folder)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory <BR>";
if (ftp_mkdir($conn_id, $remote_folder)) {
echo "successfully created $remote_folder <br>";
} else {
echo "There was a problem while creating $remote_folder <br>";
exit(0);
}
if (ftp_chdir($conn_id, $remote_folder)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "<BR>";
} else {
echo "Couldn't change directory <BR>";
exit(0);
}
}
This is the code i use. It will try change directory, if it fails, Try creating FOLDER, then try change again. Still it do not work, script will exit.
The problem with the script is, when folder is not present, it will show error message like
Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to kerala: No such file or directory in D:\sites\test.php on line 18
Couldn't change directory
successfully created kerala
Current directory is now: /kerala
Is there any way i can avoid this error in cause of FOLDER not present ?
Anyway to check presense of folder ?
Thanks,
Yujin
