i wrote a php code for, when a new user creates an account on a website, a folder is automatically created with the user email address as the folder name, Now there is an image in the folder(i.e C://localhost/vern/mikelawson@gmail.com/zeco/image.jpg
).
Note: There is a code that removes the @gmail.com
(i.e C://localhost/vern/mikelawson/zeco/image.jpg
).
Am trying to display the image from the user(mikelawson@gmail.com) folder, but it is not displaying.
it keeps displaying the image that is from the first user(mikelawson@gmail.com) folder.
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++;
}
I expected the output to be:
img src="http://localhost/vern/mikelawson/zeco/pouvoir 046.jpg"
alt="mikelawson/zeco/pouvoir 046""
not this:
img src="http://localhost/mikelawson/zeco/pouvoir 046.jpg"
alt="mikelawson/zeco/pouvoir 046""