Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

Create Folder Dynamically and Save Image to Folder in PHP

by
Category:php
php mysql
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);
}

0 Comments


Html code work in comment box


Related Post