Created
March 8, 2017 07:29
-
-
Save Mauryashubham/16053936a4d48e5555b60f1386ddbad6 to your computer and use it in GitHub Desktop.
How to upload Image in Folder using PHP [Without Database]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi all , Welcome to Maurya Tricks , Today we are going to discuss , How to upload Image in Folder using PHP [Without Database] | |
1.Make a file in notepad and save it as index.php and paste the below code. | |
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
//Upload Image | |
if(isset($_POST['cover_up'])) | |
{ | |
$imgFile = $_FILES['coverimg']['name']; | |
$tmp_dir = $_FILES['coverimg']['tmp_name']; | |
$imgSize = $_FILES['coverimg']['size']; | |
if(!empty($imgFile)) | |
{ | |
$upload_dir = 'image/'; // upload directory | |
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension | |
// valid image extensions | |
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions | |
// rename uploading image | |
$coverpic = rand(1000,1000000).".".$imgExt; | |
// allow valid image file formats | |
if(in_array($imgExt, $valid_extensions)) | |
{ | |
// Check file size '5MB' | |
if($imgSize < 5000000) | |
{ | |
move_uploaded_file($tmp_dir,$upload_dir.$coverpic); | |
echo "uploading Done"; | |
} | |
else{ | |
$errMSG = "Sorry, your file is too large."; | |
} | |
} | |
else{ | |
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<form method="post" enctype="multipart/form-data"> | |
<p><input type="file" name="coverimg" required="required" /></p> | |
<p><input type="submit" name="cover_up" style="background-color: rgb(255, 102, 0);" class="btn btn-warning" value="Upload"/></p> | |
</form> | |
</body> | |
</html> | |
Note : How to upload Image in Folder using PHP [With Database] , will be on my next post. | |
Now, Try this code…and Try to make your own new functions.Happy Coding.. | |
STAY CONNECTED FOR MORE |
Yes, Because i am not using any database for storing image data.
I am just inserting the selected image into desired folder on server.
If you want to insert image data in database,please check my other git. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can u explain how does it exactly work without showing anything on the db