如何在两个不同的文件中使用来自PHP的变量


How to use a variabile from PHP in 2 different file

我需要一些帮助来解决这个问题。我有两个PHP文件,一个是LogIn,另一个是Upload。我如何使用登录中的用户名来创建一个新的文件夹,该文件夹的用户名用于上传对象。

LogIn.php

<?php
session_start ();
$username = $_POST ['account'];
$password = $_POST ['password'];
if ($username && $password) {
    $connect = mysql_connect ( "localhost", "root", "" ) or die ( "Couldn't connect to the database" );
    mysql_select_db ( "portofoliu_database" ) or die ( "Coudn't find database" );
    $query = mysql_query ( "SELECT * FROM portofoliu_table WHERE account= '$username'   " );
    #daca sa gasit ceva sau nu
    $numrows = mysql_num_rows ( $query );
    if ($numrows != 0) {
        while ($row = mysql_fetch_assoc($query)){
            $db_account = $row['account'];
            $db_password = $row['password'];
        }
        if($username==$db_account && $password==$db_password){
            #@ - pt prob cu indexare
            @$_SESSION['account'] = $username;
            $_SESSION["logged"] = true;
            header("location: AboutMe.php");
            exit();
        }
        else
            echo "Your password is incorrected";
            $_SESSION["logged"] = false;
            header("location: LogIn.html");
            exit();
    }
    else 
        die("That user don't exists");
}
else 
    die("Please enter a username and password");
?>

和Upload_file.php

    <?php
error_reporting ( 0 );
$target_path = "uploads/"; 
$target_path = $target_path . basename ( $_FILES ['uploadedfile'] ['name'] );
$verif = 1; 
$numefile = $_FILES ['uploadedfile'] ['name']; 
$ext = substr ( $numefile, strpos ( $numefile, '.' ), strlen ( $numefile ) - 1 ); 
echo $ext . "<br>";
$extensii_bune = array (
        '.jpg',
        '.jpeg',
        '.gif',
        '.bmp',
        '.png' 
);
if (! in_array ( $ext, $extensii_bune )) {
    echo "Nu suportam extensia " . $ext;
    $verif = 0;
}
if ($verif == 0) {
    echo "nu am putut sa uploadam fisierul";
} else {
    if (move_uploaded_file ( $_FILES ['uploadedfile'] ['tmp_name'], $target_path )) {
        echo "Fisierul " . basename ( $_FILES ['uploadedfile'] ['name'] ) . " a fost uploadat"; 
    } else {
        echo "Avem probleme la uploadare!";
    }
}
?>

在upload_file.php上尝试此操作,您可能需要先创建目录$target_path . '/' . $_SESSION['account']

$target_path = $target_path . '/' . $_SESSION['account'] . '/' . basename ( $_FILES ['uploadedfile'] ['name'] );