form..php
<form id="productadd" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile" />
<input type="submit">
</form>
//image upload controller
if (isset($_FILES['imagefile']['name']) ) {
$valid_formats = array("jpg", "png", "gif", "jpeg","JPG", "PNG", "GIF","JPEG");
$name = $_FILES['imagefile']['name']; // filename to get file's extension
list($sometext, $extension) = explode(".", $name); // get the file's extension
if (in_array($extension, $valid_formats)) { // check it if it's a valid format or not
$imagename = md5(uniqid() . time()) . "." . $extension;
$tmp = $_FILES['imagefile']['tmp_name'];
if (move_uploaded_file($tmp, "uploads/users_image/" . $imagename)) {
$add_users_img = $imagename;
} else {
echo "Could not move the image file.";
}
}else {
echo "Invalid image file format.";
}
}
<form id="productadd" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile" />
<input type="submit">
</form>
//image upload controller
if (isset($_FILES['imagefile']['name']) ) {
$valid_formats = array("jpg", "png", "gif", "jpeg","JPG", "PNG", "GIF","JPEG");
$name = $_FILES['imagefile']['name']; // filename to get file's extension
list($sometext, $extension) = explode(".", $name); // get the file's extension
if (in_array($extension, $valid_formats)) { // check it if it's a valid format or not
$imagename = md5(uniqid() . time()) . "." . $extension;
$tmp = $_FILES['imagefile']['tmp_name'];
if (move_uploaded_file($tmp, "uploads/users_image/" . $imagename)) {
$add_users_img = $imagename;
} else {
echo "Could not move the image file.";
}
}else {
echo "Invalid image file format.";
}
}
No comments:
Post a Comment