Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: File Renaming

  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    197
    Thanks
    29
    Thanked 0 Times in 0 Posts

    File Renaming

    Hi,
    I have a script below, what I want todo and have NO Idea howto do it is.
    I have films named by number (ie: 123.avi) is it possibly to rename the file
    with the " {$row['Title']} " when I click download, so the file is downloaded by file name rather than number...

    Code:
    <?php
    $con = mysql_connect("localhost","root","root");if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("film_info", $con);
    $result = mysql_query("SELECT * FROM `films` WHERE TO_DAYS(TIMESTAMP) = TO_DAYS(NOW() - INTERVAL 1 DAY) ORDER BY `Title`");
    echo "<center>";
    echo "</br>";
    echo "<h1><b><font color=\"DodgerBlue\">Films Added 1 Day Ago</font></b></h1>\n";
    echo "<hr>";
     echo "Total Files:  ";
    echo mysql_num_rows($result);
    echo "<center>";
    
    echo "<body bgcolor=\"black\" text=\"DodgerBlue\" link=\"fuchsia\" vlink=\"purple\" alink=\"fuchsia\">\n";
    echo "
    
    <table border='0'>
    </center>" ;
    
    $i = 0;
    while($row = mysql_fetch_array($result))
      {
     $i++;
    
    echo "<center><h1><b><font color=\"DodgerBlue\">{$row['Title']}</font></b></h1></center>\n";
    echo "<table border=\"0\" width=\"90%\" height=\"*\">\n";
    echo "    <tr>\n";
    echo "        <td width=\"163\" height=\"153\" rowspan=\"2\">\n";
    echo "            <p align=\"left\"><img src=\"./covers/{$row['Title']}.jpg\" width=\"108\" height=\"166\" border=\"0\" vspace=\"0\" hspace=\"40\"></p>\n";
    echo "        </td>\n";
    echo "        <td width=\"100%\" height=\"30\" align=\"left\"  valign=\"top\" style=\"margin-right:0; margin-left:0;\">\n";
    echo  "<b><font color=DodgerBlue>Year: </font><font color=black>............ </font>";
    echo  "<font color=fuchsia>{$row['Year']}</font></b>";
    echo "</br>";
    echo  "<b><font color=DodgerBlue>Genre:</font><font color=black> ......... </font></b><font color=fuchsia>{$row['Extras']}</font>";
    echo "</br>";
    echo "<b><font color=DodgerBlue>Imdb:</font><font color=black> ........... </font></b><a href='{$row['IMDB']}' onclick='imdb(this.href);return false'>Visit IMDB</a>";
    echo "</br>";
    echo "<b><font color=DodgerBlue>View:</font><font color=black> ........... </font></b><a href='./filesarehere/{$row['View']}' onclick='play(this.href);return false'>View Film</a>";
    echo "</br>";
    echo  "<b><font color=DodgerBlue>Download:</font><font color=black> ... </font></b><a href=./filesarehere/{$row['Download']}>Click Here</a>";
    echo "</br>";
    echo "</br>";
    echo  "<b><font color=DodgerBlue>Plot:</br>   </font></b><font color=fuchsia>{$row['Info']}</font></b>";
    echo "        </td>    </tr>\n";
    echo "</table>";
    echo "</br>";
    echo "<hr>";
      }
      ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The only thing I can think to do is use the copy() function to copy the file to the name you want and then link to that new file.

    http://us2.php.net/manual/en/function.copy.php

    There's probably a better way...

  • #3
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Sure: rename()

    Just rename it to what you want, then name it back. Of course, then you run into problems where multiple users want to download the file at the same time...so that doesn't work. You could just create copies of the file, but that would take forever.

    There's also this suggestion.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yeah I was thinking "why not just create a symbolic link? I wonder if PHP has a function for that..."

    And TA-DA, there is the function symlink()

    http://us2.php.net/manual/en/function.symlink.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •