Jump to content

Recommended Posts

Hey, can someone tell me how to make it so when i run the script it creates a file with a new each time eg,

 

First time i run the script creates a file called: user100

 

Second time i run the script creates a file called: user200

 

3RD  time i run the script creates a file called: user300

 

and how could i create sub directorys in those files?

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/
Share on other sites

Assuming that user will always remain user,

 

Try this:

// Generate Random Numbers
$x = rand(0,100);
$y = rand(50,200);
$z = rand(200,500);

// Put them togther
$filename = "user$x$y$z";

// Check to see if file name is taken

$sql = "SELECT COUNT(*) FROM `database` WHERE `filename` = '$filename";
$result = mysql_query($sql) or die('Error checking FileName!<br />'.mysql_error());

// If we dont find a filename:

    if(mysql_num_rows($result) == '0')
       {
// Code when thsi filename is free
}
else{
// Code when this filename is not free

}

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903646
Share on other sites

Sorry,

 

I dont know any other solutions...

 

There could be, but that would be suprising as how can you know what filename is already taken or not?

 

They must be stored somewhere...

 

You could try storing them in a text file if you want...

 

But you are complicating your life....

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903658
Share on other sites

Well, I'm setting up a game server hosting company and im coding a panel and i want it to automaticaly create the users gameserver files, proferably i need a script that will create the ftp account for that file too dose anyone know how to create ftp accounts though php?

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903799
Share on other sites

Well, I'm setting up a game server hosting company and im coding a panel and i want it to automaticaly create the users gameserver files, proferably i need a script that will create the ftp account for that file too dose anyone know how to create ftp accounts though php?

 

It'll make more sense to name your directories after your users then. That way there guaranteed unique, and its much simpler to see who owns what.

 

As for giving users the ability to ftp, you can execute any required shell commands via the exec family of functions.

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903811
Share on other sites

do you know how to make it so they can register and after they can buy a server and then once they buy the server it auto create the server files and ftp the same name as there account and the control panel link appears in there user area?

Link to comment
https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903832
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.