+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP File Operations Help

  1. #1
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    PHP File Operations Help

    Hey guys, I'm trying to re-work a script written by someone (i forget their name, they are from x10)

    It gets the current song name and song length and outputs it on an image. Ok, great, however, since the headers are already sent, you can't update the image (i think... lol).

    I tried to re-work it with text, but I'm pretty sure I failed miserably.

    Heres my code:

    PHP Code:
    <?PHP
    require_once("song.txt");
    require_once(
    "length_remaining.php");
    require_once(
    "song_temp.txt");
    $file song.txt;
    $next song_temp.txt;
    $fp = @fopen($file'r');
    $song fread($fp512);
    fclose($fp);
     
    list(
    $song$length) = explode("\n"$song);
     
    $length explode(':'$length);
    $length = (intval($length[0]) * 60) + intval($length[1]);
    $length -= length() - filemlength($file);
    if (
    $length 1) {
    echo 
    "Between songs or offline";
    }
    if (
    strlen($song) > 32) {
     
    $p strrpos(substr($song032), ' ');
     
    $song = array(trim(substr($song0$p)), trim(substr($song$p)));
     if (
    strlen($song[1]) > 32) {
      
    $song[1] = substr($song[1], 032) . '...';
    echo 
    $song[1];

     }
    echo 
    $song;
    }

    }
    else {
     
    $song = array($song'');
    }
    //getnew... i hope

    if ($length <= 0) {
    $fp = @fopen($next'r');
    $nextsong fread($fp512);
    fclose($fp);
     
    list(
    $nextsongsong$length) = explode("\n"$song);
     
    $length explode(':'$length);
    $length = (intval($length[0]) * 60) + intval($length[1]);
    $length -= length() - filemlength($file);
    if (
    $length 1) {
    echo 
    "Between songs or offline";
    }
    if (
    strlen($nextsong) > 32) {
     
    $p strrpos(substr($nextsong032), ' ');
     
    $nextsong = array(trim(substr($nextsong0$p)), trim(substr($nextsong$p)));
     if (
    strlen($nextsong[1]) > 32) {
      
    $nextsong[1] = substr($nextsong[1], 032) . '...';
    echo 
    $nextsong[1];

     }
    echo 
    $nextsong;
    }
    }
    else {
     
    $nextsong = array($nextsong'');
     }
    }
    ?>
    and time_remaining.php:

    PHP Code:
    <?php
    //time_remaining.php
    if (!isset($length)) {
     
    $file 'song.txt';
     
    $fp = @fopen($file'r');
     
    $length fread($fp512);
     
    fclose($fp);
     
    $length explode("\n"$length);
     
    $length $length[1];
    }
    $length explode(':'$length);
    $length = (intval($length[0]) * 60) + intval($length[1]);
    $length -= time() - filemtime($file);
    if (isset(
    $_GET['show'])) {
     print 
    $length;
    }
    ?>
    If you could help, that would be great. I am in a rush, so i could probably do this normally...but. yeah.

    Its probably a very simple error, or just me being a noob at f-op.

    Any help is appreciated, if you give a me a new code that will do the same thing, 300 credits (or more depending on..well...stuff)

    Thanks a bunch,
    Neil
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP File Operations Help

    Change lines 5+6 of the first page to this:
    PHP Code:
    $file 'song.txt';
    $next 'song_temp.txt'
    EDIT: I can't see anything else wrong. But don't quote me on that. I'm on Vista and don't have my syntax highlighting that I'm used to on Linux! rofl.
    Well, other than the fact that you're not outputting it as an image :p

    You can output an image by doing something along the lines of the following:
    PHP Code:
    <?php
    header
    ("Content-type: image/png");
    $image imagecreatetruecolor(550200) or die("Cannot Initialize new GD image stream");

    $col_transparant imagecolorallocatealpha($image255255255127);
    imagecolortransparent ($image$col_transparant);
    $col_black imagecolorallocate($image000);

    imagefill($image00$col_transparant);
    imagestring($image5510,  "track: $track"$col_black);
    imagestring($image5550,  "length: $length"$col_black);

    imagepng($image);
    imagedestroy($image);
    and that will output a simple image, assuming that $track and $length are set

    You may also wish to create a 'template' image, which is a fancy pre-made image to use as a base.
    Just keep a space to output the text you desire, then position it correctly in your code
    Last edited by Scoochi2; 09-14-2008 at 06:54 AM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    themasterrocker Guest

    Re: PHP File Operations Help

    No, because the file is song.txt but the song_temp.txt tells the software we use how to show whats going into the song.txt so i'm sure that bit is right.

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP File Operations Help

    yeah, i don't want an image, I am most likely going to store it into a flat file db and recall the last like 5 songs or something. I'm trying to get someting like x10radio has. xD
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  5. #5
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP File Operations Help

    lol, you said you wanted it as an image!

    Anyhoo, like I said on lines 5+6 when you set the two variables, they need to be strings.
    PHP Code:
    $file "myfile.txt"
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

+ Reply to Thread

Similar Threads

  1. It works! ...
    By bpakidz in forum Programming Help
    Replies: 4
    Last Post: 09-07-2008, 11:12 PM
  2. configuring php on localhost
    By ufclan in forum Scripts & 3rd Party Apps
    Replies: 15
    Last Post: 01-22-2008, 08:34 AM
  3. Hosting A PhP File
    By Zelieo in forum Free Hosting
    Replies: 7
    Last Post: 10-30-2007, 11:35 AM
  4. php file create denied?
    By omghaxzs in forum Free Hosting
    Replies: 2
    Last Post: 09-01-2007, 06:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers