hi.
I have the

<HTML><HEAD><title>files.php</title></HEAD>
<?php
echo "elenco files disponibili:<BR>";
$cartella=dir("files");
while ($f = $cartella->read())  
{ if ($f!='.' && $f!='..') { $dest="scarica.php?nome_file=".$f; echo "<A HREF=".$dest.">scarica: ".$f."</A><BR>"; } } $cartella->close(); ?>

and the

?php			//scarica.php
header("Content-type:*");
header("Content-Disposition: inline; filename=".$nome_file);
readfile($nome_file);
exit;
?>

"files" ,"files.php" and "scarica.php" are all saved in the same dirctory

in outputwhen i click the link of one of the files to download, it returns me the fallowing error messages(for some reason ,i don't understand why, they're printed in the editor i use for writting the php scripts and not in the browser):

<br />
<b>Notice</b>: Undefined variable: nome_file in <b>D:.......scarica.php</b> on line <b>3</b><br />
<br />
<b>Notice</b>: Undefined variable: nome_file in <b>D:.......scarica.php</b> on line <b>4</b><br />

what did i do wrong??
could u pls help me?
thanks

    Okay, you're not capturing the variable.

    $dest="scarica.php?nome_file=".$f; // This line is fine
    

    There are two main ways of passing data between pages, POST and GET. There are other ways i.e. sessions and cookies, but that's not what we're looking at here.

    Whenever you see a website using a string such as the following

    <a href="path/to/my/file.php?name=dave">
    

    That's the get method.

    You need to parse these variables after the ?

    So the problem you're having here is the fact that your second php file needs to get the variable from the query string

    <?php            //scarica.php 
    
    $nome_file = $_GET['nome_file'];
    
    header("Content-type:*"); 
    header("Content-Disposition: inline; filename=".$nome_file); 
    readfile($nome_file); 
    exit; 
    ?> 
    

    Whenever you're passing any sort of data via a query string, you need to use the get method to capture the data.

    So for example

    file.php?name=dave&age=22

    your php file would need to read

    $name = $_GET['name'];
    $age = $_GET['age'];
    
    echo $name; // Would echo my name
    echo $age; // would echo my age
    

    Hope this helps

      More information/examples can be found in the manual: [man]variables.external[/man].

        Write a Reply...