Create Folder Dynamically and Save Image to Folder in PHP
In this tutorial we will make a file Upload with PHP system with verification for the create new folder and check existing folder .The system will automatically create new folder. You may also like How to create new folder using php and How to check a folder doesn’t already exist using php.
PHP Code
if(isset($_FILES['candidate_photo']) && $_FILES['candidate_photo']['size'] > 0){
$candidate_id = 1;
if (! is_dir ( './public/images/candidate/'.$candidate_id )) {
mkdir ( './public/images/candidate/'.$candidate_id, 0777, true );
}
if (! is_dir ( './public/images/candidate/'.$candidate_id.'/candidate_photo' )) {
mkdir ( './public/images/candidate/'.$candidate_id.'/candidate_photo', 0777, true );
}
$newfile = './public/images/candidate/'.$candidate_id.'/candidate_photo/'.$_FILES['candidate_photo']['name'];
copy($_FILES['candidate_photo']['tmp_name'], $newfile);
}
Leave a Reply