Pass variable to another php file

Asked

Viewed 4,049 times

0

I’m making a system where the user uploads a video and automatically already a page is created on the site with the video. I was able to upload and create the page, but I use an iframe to put the video on the page (which is generated) and to pass the src from the iframe I use the following src="folder/$new_name" the new name variable is generated by the upload file, but I can’t get the user to upload and then this variable is passed into the page generation file.

For some reason I couldn’t get the code in here, so I put it in Stebin.

Upload: https://pastebin.com/LhM4Uy2T Page generator: https://pastebin.com/Rvu8KNWv

3 answers

0

Toniotti

After uploading, what do you call the page creation file? You can pass the variable to the creation file by post or get depending on how you are calling the creation page.

Another solution would be to perform a select in the table where you inserted the video name once you perform an Insert in the database with the variable value.

0


The solution is simple, just you implement:

After uploading the file you can redirect the user to the video page and to the file that has the iframe know which video is being "prompted" you use Query String:

<?php
    include("conexao.php");

    $msg = false;

    if(isset($_FILES['arquivo'])){

        $extensao = strtolower(substr($_FILES['arquivo']['name'], -4));
        $novo_nome = md5(time()) .$extensao;
        $diretorio = "animes/";


        move_uploaded_file($_FILES['arquivo']['tmp_name'], $diretorio.$novo_nome);

        $sql_code = "INSERT INTO arquivo (codigo, arquivo, data) VALUES (null, '$novo_nome', NOW())";
        if ($mysqli->query($sql_code))
            $msg = "Arquivo enviado. <a href='gerador_paginas.php?video=".$novo_nome."'>Clique aqui</a> para gerar o HTML";

        else 
            $msg = "Falha ao enviar.";

    }
?>

After that, you recover from the URL which file name to display:

<?php
$novo_nome = $_GET['video'];

$arquivo = fopen($novo_nome, "w");
$texto = "<!DOCTYPE html>
<html lang=\"en\">
<head>
    <meta charset=\"UTF-8\">
    <title></title>
</head>
<body>
    <iframe src=\"upload/animes/$novo_nome\" frameborder=\"0\"></iframe>
</body>
</html>";
fwrite($arquivo, $texto);
?>

And also you can create as a playlist, listing the videos and always redirecting to sua_pagina.php? video=NOME_DO_VIDEO

One tip I recommend is never to use names in Query String 'cause that could be a problem up front for you. It would be nice to use the ID of the record inserted in the database referring to that video, then you take the ID via Query String and do the query in Mysql to return the video name.

I didn’t understand the need only to create an html file containing iframe, because if you have many videos, you will create many files on your server. If you just want to let the user upload the video and then make this video accessible, just create a page that takes the query string and assembles the HTML without saving a new file on your server, getting more or less like this:

<?php
$novo_nome = $_GET['video'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <iframe src="upload/animes/<?php echo $novo_nome;?>" frameborder="0"></iframe>
</body>
</html>
  • Well I create several pages so that later I can be accessible to any user, it would be like a stream site

  • One being dynamic would not meet your need? Look at this last code I posted, it makes you dynamic. Imagine that you have 1,000 generated files and you need to change the layout, that would be a headache for you.

  • But kind would have like to make this page that Voce put one for each video? Type on the index have a link to each video posted on the site.

  • There would be a link to each video, but in these links what would change is only the contents of the query string, in case ? video=NOME_ARQUVO ... In this NOME_ARQUIVO you will make dynamic, pulling the entries registered in the database and put the name in place

  • I’ll try that, vlw by the tip.

0

If you upgrade to a $_SESSION[] superglobal, unlike cookies ,it is stored on the server and Voce can share between pages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.