ChrisMartino Posted August 21, 2009 Share Posted August 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/ Share on other sites More sharing options...
Zane Posted August 21, 2009 Share Posted August 21, 2009 take a look at glob Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903642 Share on other sites More sharing options...
ChrisMartino Posted August 21, 2009 Author Share Posted August 21, 2009 hmm... sorry im totaly new to this, i looked over glob() but im not sure what to do with it the only bit i understood was that you can use it to get a filesize Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903644 Share on other sites More sharing options...
Aravinthan Posted August 21, 2009 Share Posted August 21, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903646 Share on other sites More sharing options...
Aravinthan Posted August 21, 2009 Share Posted August 21, 2009 My code is made as I assument that the filenames are stored in the DB... If not it is pratically impossible to make a different name everytime... Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903648 Share on other sites More sharing options...
ChrisMartino Posted August 21, 2009 Author Share Posted August 21, 2009 hey is there a altrenitive to mysql as i have a dedi server and i dont want to run sql if at all possible as it kind is a use on resorces Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903656 Share on other sites More sharing options...
Aravinthan Posted August 21, 2009 Share Posted August 21, 2009 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.... Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903658 Share on other sites More sharing options...
ChrisMartino Posted August 21, 2009 Author Share Posted August 21, 2009 i could do that what you told me but how would i create the table thats the only bit and how would i connect to the database? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903663 Share on other sites More sharing options...
Aravinthan Posted August 21, 2009 Share Posted August 21, 2009 Do you have PHP My Admin with your host? It would be easier for your to maintain it. Check in your control Panel Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903665 Share on other sites More sharing options...
ChrisMartino Posted August 21, 2009 Author Share Posted August 21, 2009 yea i do have that, if i pm'd you the info would you set it up for me Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903682 Share on other sites More sharing options...
ChrisMartino Posted August 22, 2009 Author Share Posted August 22, 2009 anyone know of a non-mysql alturnitave? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903702 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 sqlite. Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903714 Share on other sites More sharing options...
ChrisMartino Posted August 22, 2009 Author Share Posted August 22, 2009 i ment without the need for a database Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903766 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 You haven't actually described what (overall) your wanting to do. Are you planning on making new directories for users or something? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903767 Share on other sites More sharing options...
ChrisMartino Posted August 22, 2009 Author Share Posted August 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903799 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903811 Share on other sites More sharing options...
ChrisMartino Posted August 22, 2009 Author Share Posted August 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903832 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 Yes, I could likely program that quite easily. This blog post might help you. Until you can grasp that concept, I think your going to struggle to program such a thing. Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903842 Share on other sites More sharing options...
ChrisMartino Posted August 22, 2009 Author Share Posted August 22, 2009 would you code it for me at a price? Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903850 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 would you code it for me at a price? We have a freelance forum for such requests. I wouldn't have the time at present but you might find someone. Quote Link to comment https://forums.phpfreaks.com/topic/171350-php-random-file-name/#findComment-903852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.