View Full Version : Variables in directories
AndyA
11-27-2008, 04:02 PM
My problem is that I need a directory to be created on my ftp account (File Manager), which has the title of a variable. In other words, this is on a registration page, and I would like the directory created to be the name of the username submitted.
Here's what I have so far:
@ftp_mkdir($conn_id, '/public_html/profiles/" . $userUsername . "');
Is this possible to do? If so, how could it be done?
Thanks in advance for any help, Andy.
BabblingIdjit
11-27-2008, 05:36 PM
Try this:
$new_dir = '/public_html/profiles/' . $userUsername;
@ftp_mkdir($conn_id, $new_dir);
Suggestion: I know the user-submitted examples in the php manual (http://www.php.net/manual/en/function.ftp-mkdir.php) make use of the @ prefix to functions. But, generally, I don't believe that to be the best approach.
@ suppresses errors. It's far better in my opinion to handle the errors in your code rather than suppressing them.
motormichael12
11-27-2008, 06:06 PM
if its on the same website couldn't you jsut use mkdir?
AndyA
11-27-2008, 06:23 PM
Wow. Fantastic! :D
Thanks sooo much John. It's all working great now! :D
Couldn't have done it without you, great idea! Thanks a million.
Here's my final code for that section:
$ftp_server = $ftpserver;
$ftp_user = $ftpuser;
$ftp_password = $ftppass;
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user, $ftp_password);
if((!$conn_id) || (!$login_result))
{
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user";
}
$new_dir = '/public_html/profiles/' . $userUsername;
ftp_mkdir($conn_id, $new_dir);
$temp = tmpfile();
//Upload the temporary file to server
$new_file = '/public_html/profiles/' . $userUsername . '/' . $userUsername;
ftp_fput($conn_id, $new_file, $temp, FTP_BINARY);
ftp_close($conn_id);
BabblingIdjit
11-27-2008, 06:25 PM
Cool. you're welcome
ftp_mkdir($conn_id, "/public_html/profiles/$userUsername");
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.