Pass variable to another php file

0

I'm doing a system where the user uploads a video and automatically creates a page on the site with the video. I've been able to upload and create the page, however 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 variable new name is generated by the upload file, but I can not get the user to upload and then that variable is passed into the page generation file.

For some reason I can not put the code here, so I put it in the pastebin.

Upload: link Page Generator: link

    
asked by anonymous 03.06.2017 / 14:31

3 answers

0

The solution is simple, you simply implement:

After uploading the file you can redirect the user to the video page and to the file that has the iframe knowing which video is being "requested" 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 retrieve the URL of the file to be displayed from the URL:

<?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 your_page.php? video = VIDEO_NAME

One tip I recommend is never to use names in Query String as this can be a problem up front for you. It would be nice to use the ID of the record inserted in the database for that video, then you get the ID via Query String and query in MySQL to return the name of the video.

I do not understand the need only to create an html file containing the iframe, because if you have many videos, it will create many files on your server. If you just want to let the user upload the video and then leave that video accessible, just create a page that takes the query string and mount the HTML without saving a new file on your server, going something 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>
    
03.06.2017 / 15:13
0

Toniotti

After the upload as the page creation file calls? You can pass the variable to the creation file per post or get depending on how you are calling the creation page.

Another solution would be to perform a select on the table where you entered the name of the video once it performs an insert in the bank with the value of the variable.

    
03.06.2017 / 14:58
0

If you grade to a superglobal $ _SESSION [], different from cookies, it stays on the server and you can share between pages.

    
03.06.2017 / 15:21