Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: HELP needed with php codes

  1. #1
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default HELP needed with php codes

    In the following php code to embed wmv file in a webpage, is it possible to list more than one wmv file (so that I do not have to create one php file for each very one wmv file)? Would appreciate if someone could help. Thank you.

    <?php
    $file = $_REQUEST["file"];

    if ($file == "something") {
    $open = 'trial.wmv';
    }

    else {
    $open = ' ';
    }

    Header("Content-type: video/x-ms-wmv");

    echo $open;
    ?>

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    <?php
    $file = $_REQUEST["file"];
    //info about music files is stored
    $farray (
    one=>a.wmv,
    two=>b.wmv,
    three=>c.wmv
    )
    // file not (!=) null ("")
    if ($file != "") {
    $open = $farray[$file];
    }

    else {
    $open = ' ';
    }

    Header("Content-type: video/x-ms-wmv");

    echo $open;
    ?>
    the url would be request.php?file=(aray key name, one/two/three ect.)
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your input but there is an error here:
    Parse error: parse error, unexpected T_DOUBLE_ARROW on line 5

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by boxxertrumps View Post
    $farray (
    one=>a.wmv,
    two=>b.wmv,
    three=>c.wmv
    )
    Anything in the array must have quotes around it, or it will cause errors. Also, at the end of the array, you must have a semicolon. All of the corrections to the above quoted code are posted below in red.

    Code:
    $farray (
    'one' => 'a.wmv',
    'two' => 'b.wmv',
    'three' => 'c.wmv'
    );
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your input but the same error message still appear:
    Parse error: parse error, unexpected T_DOUBLE_ARROW on line 5

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Did you copy and paste the code that boxxertrumps posted, or did you just add that to a code that you already had? If you copied and pasted, line 5 is the first line of the array. Otherwise, we would need to see the code in order to find a solution.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    I copied and pasted boxxertrumps' code and replaced the one which you corrected:

    <?php
    $file = $_REQUEST["file"];
    //info about music files is stored
    $farray (
    'one' => 'a.wmv',
    'two' => 'b.wmv',
    'three' => 'c.wmv'
    );
    // file not (!=) null ("")
    if ($file != "") {
    $open = $farray[$file];
    }

    else {
    $open = ' ';
    }

    Header("Content-type: video/x-ms-wmv");

    echo $open;
    ?>

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... looks ok to me, not sure, though.

    But.... umm... echo $open means echo 'a.wmv', not actually output the file...

    There are several other functions in php that can do this.

    For example--
    echo file_get_contents($open);

    However, I think there may be a more preferable function, but not sure.


    Also, $file = $_REQUEST["file"]; is overkill. That leaves it open to cookies, post and get data, when you only need get (URL, like ...?var=value). (cookies are stored text files to set preferences for a user, etc., and post data is from a form (get can be too, but it is then sent as part of the url, not hidden, like post).
    $file = $_GET["file"]; would do just fine.
    REQUEST isn't really hurting, but I don't see any reason it would help.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for your input, I greatly appreciate it.

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, so I found the reason for your error message that appears with the script. The original is below and the correction is below that in red.

    Code:
    <?php
    $file = $_REQUEST["file"];
    //info about music files is stored
    $farray (
    'one' => 'a.wmv',
    'two' => 'b.wmv',
    'three' => 'c.wmv'
    );
    // file not (!=) null ("")
    if ($file != "") {
    $open = $farray[$file];
    }
    
    else {
    $open = ' ';
    }
    
    Header("Content-type: video/x-ms-wmv");
    
    echo $open;
    ?>
    Correction:

    Code:
    <?php
    $file = $_REQUEST["file"];
    //info about music files is stored
    $farray = array(
    'one' => 'a.wmv',
    'two' => 'b.wmv',
    'three' => 'c.wmv'
    );
    // file not (!=) null ("")
    if ($file != "") {
    $open = $farray[$file];
    }
    
    else {
    $open = ' ';
    }
    
    Header("Content-type: video/x-ms-wmv");
    
    echo $open;
    ?>
    I completely overlooked that the code had an array, but the array was never started. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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