使用刚刚创建帐户的用户的电子邮件创建文件夹,并显示用户电子邮件中的图像';使用php创建文件夹
我编写了一个php代码,当新用户在网站上创建帐户时,会自动创建一个文件夹,并将用户电子邮件地址作为文件夹名称,现在文件夹中有一个图像(即使用刚刚创建帐户的用户的电子邮件创建文件夹,并显示用户电子邮件中的图像';使用php创建文件夹,php,email,directory,filenames,subdirectory,Php,Email,Directory,Filenames,Subdirectory,我编写了一个php代码,当新用户在网站上创建帐户时,会自动创建一个文件夹,并将用户电子邮件地址作为文件夹名称,现在文件夹中有一个图像(即C://localhost/vern/mikelawson@gmail.com/zeco/image.jpg) 注意:有一个代码删除@gmail.com (即C://localhost/vern/mikelawson/zeco/image.jpg) 我正在尝试显示来自用户的图像(mikelawson@gmail.com)文件夹,但它不显示 它会一直显示来自第一个
C://localhost/vern/mikelawson@gmail.com/zeco/image.jpg
)
注意:有一个代码删除@gmail.com
(即C://localhost/vern/mikelawson/zeco/image.jpg
)
我正在尝试显示来自用户的图像(mikelawson@gmail.com)文件夹,但它不显示
它会一直显示来自第一个用户的图像(mikelawson@gmail.com)文件夹
不是这个:
img src="http://localhost/mikelawson/zeco/pouvoir 046.jpg"
alt="mikelawson/zeco/pouvoir 046""
如何设置$email变量?因为我在你写的代码中没有看到任何东西。 同时放置(在foreach之前): 并粘贴输出
// Finally, register user if there are no errors in the form
if (count($errors) == 0) {
$email = mysqli_real_escape_string($db, $_POST['email']);
$nest = $email;
if ($user['email'] !== $email) {
$userfname = substr($email, 0, strpos($email, '@'));
(!mkdir($userfname, 0777, true));
}
$password = md5($password_1);//encrypt the password before saving in the database
$query = "INSERT INTO users (username, email, user_number, password)
VALUES('$username', '$email', '$user_number', '$password')";
mysqli_query($db, $query);
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
The below is for displaying the image(s):
$email = "";
$base_url = 'http://localhost/vern/';
$userfname = substr($email, 0, strpos($email, '@'));
$dir = $userfname."*/zeco/*";
$files = glob($dir);
usort( $files, function( $a, $b ) { return filemtime($b) - filemtime($a); } );
$i = 1;
foreach($files as $file) {
$remove_ext = substr($file, 0, strrpos($file, "."));
if($i <= 1 AND $i >= 1){
echo '<img src="'.$base_url.$file.'" alt="'.$remove_ext.'" style="width:45px;height:45px;border-radius:10px;"></br>';
}
$i++;
}
img src="http://localhost/vern/mikelawson/zeco/pouvoir 046.jpg"
alt="mikelawson/zeco/pouvoir 046" "
img src="http://localhost/mikelawson/zeco/pouvoir 046.jpg"
alt="mikelawson/zeco/pouvoir 046""
var_dump($files);