Saturday 28 May 2016

How to upload image in php?

How to upload image in PHP

How to upload image in PHP

Hello, friends today we are going to learn about the submission of forms with files. This is too easy and simple while you are doing coding. so don't be afraid it's simple and easy programmatically I will teach you here each and every step in detail. so your concepts will be clear.

while you are working in PHP first you need to start your server so that the code will be run on the server. So I assume that you now the server and know how to start the server and run your code in that.

How to upload image in php?

HTML

<html>
<head>
<title>A simple example of uploading a file using PHP script</title>
</head>
<body>
<b>Simple example of uploading a file</b><br />
Choose a file to be uploaded<br />
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<input type="text" name="ASDF" size="50" />
<br />
<input type="submit" value="Upload" />
</form>
</body>
</html>

PHP

You can upload the file using the PHP in the folder which you gave the path and you also need to save the name of a file in the database table so that you can then use the name again.

<?php
 if(!empty($_FILES['file'])){
    $targetfolder = "assets/";
    $file_name = $_FILES['file']['name'];
    $file_temp = $_FILES['file']['tmp_name'];
    echo "<pre>";print_r($_FILES);
    if($_FILES['file']['error'] == 0){
        move_uploaded_file($file_temp, $targetfolder.$file_name);  
        echo "The file ". $_FILES['file']['name']. " is uploaded";  
    }
    else {
       echo "Problem uploading file";
    }
 }
 ?>

Now this is the easiest way to upload the file in custom PHP that is you require the
  • file_name 
  • file_temp 
  • target folder 
and the PHP function move_upload_file which take the arguments and upload the file. also remember that the path you provide should be writeable. You can search with these queries in google for studying more material. Search for these strings upload image PHP tutorial, upload image PHP example, upload image PHP MySQL, upload image PHP MySQL tutorial, upload image Php jquery, upload image PHP stack overflow, android upload image PHP, PHP image upload script and much more can help you for searching the things. You can further read about the configure and install lamp server.
Configure Lamp server..!

This Post Was Last Updated On September 30, 2016, By Author: Mahira Khan.

0 comments:

Post a Comment

Item Reviewed: How to upload image in php? Rating: 5 Reviewed By: admin