My Name Is Salman Masood , I am Computer Science &Amp; Maths Graduate from University of Karachi, Pakistan , Teaching Is My Passion and My Aim Is to Deliver All My Knowledge among Those Students Who Can'T Afford Tutors or Expensive Institute Fees. I Will Be Keep Sharing My All Knowledge and Information with You .... Remember Me in Your Prayers !
Sunday, 1 July 2018
How to Upload image in PHP
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>File Upload</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<table> <tr> <td><input type="file" name="image"/> </td> <td> <button name="btn">Upload </button> </td> </tr> </table>
</form>
<?php
if(isset($_POST['btn']))
{
if(isset($_FILES['image']))
{
//FILENAME ,FILESIZE, FILETYPE,FILEEXTENSION...........
//-------------------------------------------------------------------------------
$errors;
// $file_name=$file_size=$file_type="";
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
//-------------------------------------------------------------------------------
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false) // values are equal so return true
{
$errors="extension not allowed, please choose a JPEG or PNG file.";
}
else
{
if($file_size > 2097152)
{
$errors='File size must be excately 2 MB or lesser...';
}
else
{
$rand=rand();
move_uploaded_file($file_tmp,"uploads/".$rand.$file_name);
}
}
if(empty($errors))
{
echo "<p style='color:green'> File Uploaded...</p>";
}
else
{
echo "<p style='color:red'> File not Uploaded...</p>";
}
}//IF FILE CONTAINS.................
else
{
echo "<p style='color:red'> plz select a FILE.....</p>";
}
}
?>
</body>
</html>
Subscribe to:
Post Comments (Atom)
Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC
Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...
-
Load event: pictureBox3.Image = Image .FromFile( @"C:\Users\salman\Documents\Visual Studio 2013\Projects\WindowsFormsApplication3\W...
No comments:
Post a Comment