Urgent PHP help needed

Discussion in 'PHP' started by jibreel, Aug 1, 2012.

  1. #1
    Hey guys,
    Im trying to make the following work but without succes so far..
    I'm working on a page where people download mp3 files that are being converted
    from youtube videos in realtime after they pasted the youtube url into a textfield and hit the CONVERT NOW button.
    The video starts to convert and a download link to the MP3 file appears. This all works..


    What I would like to accomplish is:


    When the visitor clicks on the DOWNLOAD MP3 FILE button, an offer appears on the screen where the visitor fills out their e-mail address.
    When they have succesfully done that, the visitor should be redirected to the page that holds the link to the MP3 file that they had converted before.


    Here is the original script :

    <?php
            // On form submission...
            if ($_POST['submit'])
            {
                // Print "please wait" message and preview image
                echo '<div id="preview" style="display:block"><p>...Please wait while I try to convert:</p>';
                echo '<p><img src="http://img.youtube.com/vi/'.$converter->ExtractVideoId(trim($_POST['youtubeURL'])).'/1.jpg" alt="preview image" /></p>';
                echo '<p>'.$converter->ExtractSongTrackName(trim($_POST['youtubeURL']), 'url').'</p>';
                echo '<div id="progress-bar"><div id="progress">0%</div></div></div>';
                flush();
    
    
                // Main Program Execution
                if ($converter->DownloadVideo(trim($_POST['youtubeURL'])))
                {
                    echo ($converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</p><p><a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).'">CONVERT NOW</a></p>' : '<p>Error generating MP3 file!</p>';
                }
                else
                {
                    echo '<p>Error downloading video!</p>';
                }
            }
        ?>
    PHP:



    This would call instantly for the MP3 file to download without the offer appearing.
    I would like the part where it says "Download your MP3 file." to be exchanged with the following:


    The script that triggers the javascript to make the offer appear:

    
    <a href="#" onClick="javascript:initGateway(); return false;">Click here</a>
    
    HTML:
    The script that is being activated when "initGateway()" is called for.

    
      <script type="text/javascript">var gwloaded = false;</script>
      <script src="#" type="text/javascript"></script>
      <script type="text/javascript">if (gwloaded==false){window.location = "#";}</script>
      <noscript><meta http-equiv="refresh" content="0;url=#" /></noscript>
      
    
    
    
    HTML:
    Once the visitor fills in their email address, they will be redirected to "download.php" where I would like the link to the MP3 file that was generated to become visible and downloadable.


    I hope someone can help me out to find an anwser.
    I really appreciate all the help much!
     
    Last edited: Aug 1, 2012
    jibreel, Aug 1, 2012 IP
  2. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #2
    Unfortunately, the reference you gave for the initGateway() function seems to be nothing more than a few <script> tags that will always simply changes the window location to '#'. Can you attach the code for the actual initGateway() function for debugging?

    Also, this is more of a javascript issue from the looks of it.
     
    Thorlax402, Aug 1, 2012 IP
  3. jibreel

    jibreel Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,
    I replaced the original links to the sponsor with "#" because it is not necessary to show them.
    I don't think you get the point, I'm asking how I can make the generated link appear on a second page rather than on the script example.The generated link will be placed on download.php
    I'd like the generated link to become visible and working on download.php


    Any idea how to do this? I am stuck :/.
     
    jibreel, Aug 1, 2012 IP
  4. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #4
    Forgive me if I'm still missing something, but wouldn't you just place the main execution into the download.php file?

    // Main Program Execution
    if ($converter->DownloadVideo(trim($_POST['youtubeURL'])))
    {
        echo ($converter->GenerateMP3($_POST['quality'])) ? '<p>Success!</p><p><a href="'.$_SERVER['PHP_SELF'].'?mp3='.urlencode(trim(strstr($converter->GetSongFileName(), '/'), '/')).'">CONVERT NOW</a></p>' : '<p>Error generating MP3 file!</p>';
    }
     else
    {
        echo '<p>Error downloading video!</p>';
    }
    PHP:
    Obviously the $_POST variable would need to be passed to the new page (most likely via the query string), but is there a reason you can't do it this way? You make it sound as though you are looking to put the link there from the original php file.
     
    Thorlax402, Aug 1, 2012 IP
  5. jibreel

    jibreel Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I understand where you are coming from but unfortunately you are still missing the point haha.
     
    jibreel, Aug 3, 2012 IP