How to Image Upload in PHP With Folder Create

if(isset($_FILES['profile_photo']) && $_FILES['profile_photo']["name"]!=""){

$folderPath = '../../uploads/patients/';
if (!is_dir($folderPath)) {
mkdir($folderPath, 0777, true);
}

$file_name = $_FILES['profile_photo']['name'];
$tmp = explode('.', $file_name);
$extension = end($tmp);
$image = rand(10,1000000000)."-".$date."-image." . $extension;
$upload = move_uploaded_file($_FILES['profile_photo']['tmp_name'], $folderPath . $image);

if ($upload) {
$profile_photo = 'uploads/patients/' . $image;
} else {
$profile_photo = $_POST['old_photo'];
}
}else{
$profile_photo = $_POST['old_photo'];
}

3 Comments

Image
Killian Mider
Jul 22, 2023 | 7:10 PM

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam.

Image
Everly Leah
Jul 23, 2023 | 7:10 PM

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.

Image
Michel Ohio
Jun 14, 2023 | 7:10 PM

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam.

Leave A Comment

Your email address will not be published. Required fields are marked.