我需要一些问题的帮助。我有2个PHP文件,一个使用LogIn,另一个使用上传。如何使用LogIn中的用户名创建一个新的文件夹,其中包含上传对象的用户名。
的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!";
}
}
?>
答案 0 :(得分:0)
在upload_file.php上试试这个,你可以先创建目录$target_path . '/' . $_SESSION['account']
。
$target_path = $target_path . '/' . $_SESSION['account'] . '/' . basename ( $_FILES ['uploadedfile'] ['name'] );