我写了一个php代码,当一个新用户在网站上创建一个帐户时,会自动使用用户电子邮件地址作为文件夹名称创建一个文件夹,该文件夹中现在有一个图像(即{{1} }。
注意:有一个代码可以删除@ gmail.com
(即C://localhost/vern/mikelawson@gmail.com/zeco/image.jpg
)。
正在尝试显示用户(mikelawson@gmail.com)文件夹中的图像,但未显示。
它一直显示来自第一个用户(mikelawson@gmail.com)文件夹的图像。
C://localhost/vern/mikelawson/zeco/image.jpg
The code below is for creating the folder:
// 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" "
答案 0 :(得分:0)
如何设置$ email变量?因为我在您编写的代码中什么都看不到。 还要放置(在foreach之前):
var_dump($files);
并粘贴输出