Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/104412-solved-help-with-mkdir-function/
Share on other sites

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.

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.

 

<?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

 

 

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]

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.