View Full Version : Resolved Auto Creating A File in Directory
arsenalbates
12-28-2010, 12:56 PM
Hey. i want to set-up a way of creating or even moving an existing file to a directory on user login.
For example, the user logs in and if a directory hasn't been made, its made and a few files go into it. next time the user refreshes the folder will be created and there will be some files such as index.php in there so they can get going.
Any help would be appreciated
Many Thanks
Sam
Schmoopy
12-28-2010, 01:11 PM
So do you want it to create a new directory for a user when they first log in, and then when they login after that, more files will be added?
Here's how you can do it after a successful login, might not be exactly what you're looking for. But please explain in more detail if this isn't what you're after:
<?php
// For this example, I'll just set it to my username
$username = 'Schmoopy';
// Code to authenticate login above
// The code below assumes the user logged in successfully
// And that the username is stored in the variable $username
$path = 'users/' . $username;
if(!is_dir($path)) {
// If the directory does not exist, create it
mkdir($path);
} else {
// Code to add files / refresh files here
}
?>
The code above will only handle the creating of a new directory, not creating new files within that directory.
Please specify exactly what files you want to be put in the newly created folder.
arsenalbates
12-28-2010, 01:27 PM
hey. I want to set-up a way of creating or even moving an existing file to a directory on user login.
For example, the user logs in and if a directory hasn't been made, its made and a few files go into it. Next time the user refreshes the folder will be created and there will be some files such as index.php in there so they can get going.
Any help would be appreciated
many thanks
sam
solved !!!!!!
arsenalbates
12-28-2010, 01:28 PM
Thanks !
captainjustin
01-09-2011, 10:02 PM
How do you put the existing files in the directory? Let's say if you wanted to copy a file called image_upload.php and album.php ....... How would you do that?
PHP copy( string $source , string $dest [, resource $context ] ) (http://us3.php.net/manual/en/function.copy.php)
captainjustin
01-09-2011, 11:29 PM
Nile I'm still pretty New to all this can you be a little more specific.... I followed your link and I tried to put it together myself with no luck... The directory "Schmoopy" was created, but no files were inside the directory... This is what I tried.
<?php
// For this example, I'll just set it to my username
$username = 'Schmoopy';
// Code to authenticate login above
// The code below assumes the user logged in successfully
// And that the username is stored in the variable $username
$path = 'users/' . $username;
if(!is_dir($path)) {
// If the directory does not exist, create it
mkdir($path);
} else {
// Code to add files / refresh files here
$file = 'image_upload.php';
$newfile = 'image_upload2.php';
if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}
}
?>
Was there a file in the root directory names image_upload2.php? I'm pretty sure you want it to upload in the Schoompy folder, correct?
copy($file, $path."/".$newfile);
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.