mr_cup Posted May 6, 2008 Share Posted May 6, 2008 Hey, I was wondering if any one here could help me out with the mkdir function.. Is it possible to have mkdir create a new directory that is always +1 to the one before it automatically? E.g. If the first was tor/0 the next time the script was execute it would create tor/1 and so on..? [i'd paste the mkdir code I already have but it doesn't do what I want or even close so I figure there's no point including it] Also if it could create or copy a predetermined index.php page in the directory? Then later on some how combine it that with the script below; <?php $desc = $_POST["desc"]; $genre = $_POST["genre"]; $title = $_POST["title"]; print("<b>Alright.. Go back to /TIT</b>"); $descfile = fopen("desc.txt", "w"); $genrefile = fopen("genre.txt", "w"); $titlefile = fopen("title.txt", "w"); if (!$descfile || !$genrefile || !$titlefile) { die("Could not append to file"); } fwrite($descfile, $desc); fwrite($genrefile, $genre); fwrite($titlefile, $title); fclose($descfile); fclose($genrefile); fclose($titlefile); ?> I know this is a lot of work for anyone to do for a new member who's contributed nothing, but I've wanted to learn PHP for a long time now, but the script above is the best I've managed so far.. But even then I only have that script because I had help from a member of another forum. Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/ Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 What is to be placed into the generated folders (tor/0, tor/1, tor/2 etc). Are you wanting to create the files desc.txt, genre.txt and title.txt in those folders? Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-534514 Share on other sites More sharing options...
mr_cup Posted May 6, 2008 Author Share Posted May 6, 2008 I'm trying to create a script for a friend to upload torrents and a description of said torrent easily.. The information the script I posted before, writes to three text files that are included on a index.php page. So yeah, I think so, It would be http://www.mysite.com/tor/1 and in the "1" directory [that the mkdir created], I think there would be the three text files, and the torrent file. But honestly, I've not a clue what I'm going on about though so if that doesn't make sense, sorry. Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-534543 Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 What I'd do is actually use a flat file database rather than creating new instances of desc.txt, genre.txt and title.txt within a generated directory. I'd then use mod_rewrite so http://www.mysite.com/tor/1 will actually call http://www.mysite.com/torrent_info.php?tor=1 The torrent_info.php script will retrieve the torrent id number which it'll use to retrieve the information based on the torrent in the flat file database. Sounds complicated. But it is in fact relatively straight forward. Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-534562 Share on other sites More sharing options...
mr_cup Posted May 6, 2008 Author Share Posted May 6, 2008 Indeed it does.. Any chance you could give me an example of what to do? I know its a lot to ask and I'm sure you have better things to do but, don't ask don't get.. Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-534564 Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 <?php // check that the 'tor' parameter exists and that it holds a numeric value if(isset($_GET['tor']) && is_numeric($_GET['tor'])) { $tid = $_GET['tor']; // load the torrents.db file into the $torrents array // we use the line number as the torrent identifier $torrents = array_map('trim', file('torrents.db')); // check to see if the requested torrent identifier exists // we also check to see if the torrent hasn't been removed if(isset($torrents[$tid]) && ($torrents[$tid] != '-- removed --')) { // torrent identifier exists, get the info about the torrent list($description, $genre, $title) = explode('|', $torrents[$tid]); // now we display the torrent info in a simple HTML Table ?> <h1>Torrent Info</h1> <table border="0" cellspacing="2" cellpadding="5"> <tr> <th>Title</th> <td><?php echo $title; ?></td> </tr> <tr> <th>Genre</th> <td><?php echo $genre; ?></td> </tr> <tr> <th>Description</th> <td><?php echo $description; ?></td> </tr> </table> <?php } // torrent doesn't exist display error else { die('Torrent does not exist'); } } ?> RewriteEngine On RewriteRule ^tor/([0-9]+)$ torrent_info.php?tor=$1 [L] torrent1desc|torrent1genre|torrent1title -- removed -- torrent3desc|torrent3genre|torrent3title Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-534648 Share on other sites More sharing options...
mr_cup Posted May 7, 2008 Author Share Posted May 7, 2008 Thanks for taking time to do that, one questions though, what happens when it gets to tor/10 or higher? Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-535088 Share on other sites More sharing options...
wildteen88 Posted May 7, 2008 Share Posted May 7, 2008 Thanks for taking time to do that, one questions though, what happens when it gets to tor/10 or higher? It'll still work with more than one number, eg: mysite.com/tor/10053388 will call mysite.com/torrent_info.php?tor=10053388 Whatever is after tor/ in the url will be sent to torrent_info.php. All this is controlled by the following simple line in the .htaccess file: RewriteRule ^tor/([0-9]+)$ torrent_info.php?tor=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-535342 Share on other sites More sharing options...
mr_cup Posted May 8, 2008 Author Share Posted May 8, 2008 Ah, makes sense. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/#findComment-536150 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.