PHP File Uploading

PHP File Uploading In Hindi – PHP File Upload In Hindi

PHP

PHP File Uploading In HindiFile Upload In Hindi :- PHP Script file Ko Upload Karne Ke Liye HTML Form ka Istemal karti hai And Uske Bad Use Fir Server Par Sand Karti hai |

Waise Har Website Mai Uploading Karne Ke Liye Kuch Na Kuch Hota Jarur Hai Isliye FIle Uploading Part Or Bhi Important Ho Jata Hai |

PHP File Uploading In Hindi

File Ko Upload Karna Hoto Post Method Ki Hi Jarurat Padti Hai | enctype mai multipart/form-data ye file uploading ke liye Istemal Kiya Jata Hai |

Form Ko Upload Karna Hai To HTML input type ‘file’ Hoga Or Name ‘image’ Gaya hai, Is input attribute ke Jariye Hi PHP Se File Or Operation Kiya Jata Hain |

HTML File Uploading Form:

<html>
   <body>
      
      <form action = "" method = "POST" enctype = "multipart/form-data">
         Select A Image : <input type = "file" name = "image" /><br>
         <input type = "submit"/>
		
      </form>
      
   </body>
</html>

Output:

PHP File Upload In Hindi

Ab Ham PHP Me Main Logic Likhte Hai Or Ek Ek Point Ko Understand Karte Hai |

PHP Me 1 SuperGlobal PHP Variable Hota Hai Uske Name Hai $_FILES. Yah Variable Double Dimension Array() Hota Hain And Ye Uploaded Hone Wali File Ki Sari Information Array Ke Rup Me Store Karta Hai |

Iske Ek Ek Functions Ko Understand Karte Hai |

  • $_FILES[‘file’][‘tmp_name’] − the uploaded file in the temporary directory on the web server.
  • $_FILES[‘file’][‘name’] − the actual name of the uploaded file.
  • $_FILES[‘file’][‘size’] − the size in bytes of the uploaded file.
  • $_FILES[‘file’][‘type’] − the MIME type of the uploaded file.
  • $_FILES[‘file’][‘error’] − the error code associated with this file upload.

Example:

<?php
  // uploading a file
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $file_ext = pathinfo($file_name);
      
      $extensions= array("jpeg","jpg","png");
      
     // check extensions 
      if(in_array($file_ext,$extensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }
      
     // create a condition to check file size
      if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
      }
      
     // check empty $errors is true then upload a file
      if(empty($errors)==true) {
         move_uploaded_file($file_tmp,"images/".$file_name);
         echo "Success";
        
        // Show Display Error
      }else{
         print_r($errors);
      }
   }
?>

Aap Dekh Sakte Hain Hamne PHP File Uploading Ke Code Ko Likh Liya Hain

Final Coding With Example:

<?php
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $file_ext = pathinfo($file_name);
      
      $extensions= array("jpeg","jpg","png");
      
      if(in_array($file_ext,$extensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }
      
      if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
      }
      
      if(empty($errors)==true) {
         move_uploaded_file($file_tmp,"images/".$file_name);
         $succ = "Success";
      }
      
   }
?>
<html>
   <body>
      
      <form action = "" method = "POST" enctype = "multipart/form-data">
         <input type = "file" name = "image" />
         <input type = "submit"/>
			
         <ul>
            <li>Sent file: <?php echo $_FILES['image']['name'];  ?>
            <li>File size: <?php echo $_FILES['image']['size'];  ?>
            <li>File type: <?php echo $_FILES['image']['type'] ?>
         </ul>
			
      </form>
      
   </body>
</html>

Output:

Yadi Aapne  HTML Full Course  And CSS Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

1 thought on “PHP File Uploading In Hindi – PHP File Upload In Hindi

Leave a Reply

Your email address will not be published. Required fields are marked *