я написал php-код для: когда новый пользователь создает учетную запись на веб-сайте, автоматически создается папка с адресом электронной почты пользователя в качестве имени папки. Теперь в папке есть изображение (т.е. C://localhost/wecojo/mikelawson@gmail.com/pp/image.jpg
).
Примечание. Существует код, который удаляет @ gmail.com (т. Е. C://localhost/wecojo/mikelawson/pp/image.jpg
).
Я пытаюсь отобразить изображение из папки пользователя (mikelawson@gmail.com), но он не отображается.
он продолжает отображать изображение из папки первого пользователя (maxillarious@gmail.com).
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/wecojo/';
$userfname = substr($email, 0, strpos($email, '@'));
$dir = $userfname."*/pp/*";
$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/wecojo/mikelawson/pp/pouvoir 046.jpg"
alt="maxillarious/pp/pouvoir 046" "
не это:
img src="http://localhost/wecojo/maxillarious/pp/pouvoir 046.jpg"
alt="maxillarious/pp/pouvoir 046""