Thursday, 28 June 2018

PHP File uploads example with Source Code

Easy File Uploads in PHP Application.

There are some simple steps, you can done file upload in PHP applications

Step 1 : 

Create your Form, Additionally add attributes in form element.

Step 2: 

When your form submits, action page will be redirected, that page received all form values

 receive normal form values as usual format $var=$_POST["formcontrolname"]; metods
Note 1:

This section Using ,PHP File uplaods, have there are 4 methods
$_FILE["file"]["name"]               // This is choosing filename
$_FILE["file"]["type"]                 // This file type, png,pdf,doc,jpg
$_FILE["file"]["size"]                 // this is file size , Its take KB, you can convert MB format
$_FILE["file"]["tmp_name"]       // This is temp file,

Note 2:

If you restricted, allow some format files only uploaded in server, you can check if condition file type is JPG then upload files,

if you restricted, allow some limit size files only uploaded in server, you can check  if condition file size is "1000KB" then upload files,

if your not check, that is any kind of files uploaded then , need not to check any conditions

Step 3:

Next create uploading file to save some directory or folder, that folder create in your root directory, and assign target file path with uploading filename,

$uploadfildir="../products/".$_FILE["file"]["name"];
$target_file = $uploadfildir;

Step 4:

Finally you can store values in database, write connection and query methods, if query executes, then file is uploaded in your server

use move_uploaded_file() method,

Step 5

Finish,



Source Code

The above steps are using below examples, you can copy paste run your server,

Create products folder in root directory in your server,

Create products table in mysql, 

then create forms,

product.php

<form role="form" method="post" action="product_add.php" enctype="multipart/form-data">
   Category Name  <input type="text" name="categoryname"  placeholder="Enter Category Name">
   Product Name<input type="text" name="productname"  placeholder="Enter Product Name">
   Product Picture<input type="file" name="file"   placeholder="Choose file Name">
    <input type="submit" name="submit" value="ADD PRODUCT" class="btn btn-default"/>    
</form>


in action page, receive all form values, and store mysql table, and file uploaded in products folder,

product-save.php


<?php
$categoryname=$_POST["categoryname"];
$productname=$_POST["productname"];
$pic="JS-".$productname."-".$_FILES["file"]["name"];
$uploadfildir="../products/".$pic;
$target_file = $uploadfildir;
include("config.php");
 $insertsql="insert into products values('','$categoryname','$productname','$productpic')";
 $insertsqlres=mysqli_query($con,$insertsql);
 if($insertsqlres)
{
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file))
   {
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
   }
}
else
{
echo "Products not added!";
}
?>


Monday, 25 June 2018

PHP- How to convert PHP application to exe (Windows Application)

Hi Dear friends

Many more websites and blogs and forums to check more option for PHP application is convert into desktop application..That time we have more doubts and more questions comes out in mind.. 

A most peoples strongly challenged "PHP to EXE Conversion is Possible ot Not?" 

A Result is "Not"

Its most peoples sharing as for reason is, PHP is scripting language, to make web based application,  Not a desktop application.

But We can use PHP application both Desktop and Web Based 


Here am explained PHP Application is used to Desktop mode, in following steps

Step 1 :

Create your PHP application, and Testing your Xampp server,

Step 2 :

To Set Xampp server is Automatic Running Mode, Bcoz when your system starts, server also started,

Step 3

Copy Paste Google Chrome browser in your desktop,

Next right click, icon properties, and open properties window, in target section in end of line,




to set --app=http://localhost/yourPHPprojectname/

After to change icon, 

Step 4:

Finally you click that icon,your PHP application working in EXE format, Its look like window application, No URLS, Address section, etc


Thank you.. we will see another important topics



PHP- Step by Step To Store and Retrieve Tamil Fonts in PHP and MySQL?

PHP- How to Store and Retrieve Tamil Fonts in PHP and MySQL?


In this post explained for how to store and retrieved tamil fonts in PHP and MySQL database.  here explain step by step

Previous post explained how to display tamil fonts in webpage in detailed.. that way first design in form in your webpage

Step 1: Design form in your (HTML ) Webpage


Step 2 :   Below code copy and save customers.php



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Add New Customers</h2>
  <form name="customer" method="post" action="customers-add.php">
        <table>
         <tr><td>பெயர் </td><td><input type="text" name="cname" required /></td></tr>
        <tr><td>தொழில் </td><td><input type="text" name="occupation" required/></td></tr>
        <tr><td>விலாசம் </td><td><input type="text" name="address" required/></td></tr>
         <tr><td>ஊர் பெயர்  </td><td><input type="text" name="city" required/></td></tr>
        <tr><td>கைபேசி எண்  </td><td><input type="text" name="mobile" required/></td></tr>
        
        <tr><td></td><td><input type="submit" name="submit" value="SAVE CUSTOMER" /></td></tr>
        </table>
        </form>
</body>
</html>






Step 3 : 

Create Table in MySQL Database, just fieldname, length, additional SET as collation is
utf8_general_ci





Step 3 : 

Tables created successfully then go to coding action page


Step 4: 

Action page customers-add.php

<?php       
                 $cname=$_POST["cname"];
$occupation=$_POST["occupation"];
$address=$_POST["address"];
$city=$_POST["city"];
$address1=$address.",".$city;
$mobile=$_POST["mobile"];
$cusid=$branchcode."-$cname";

include("config1.php");
$q="insert into customers values('','$cname','$occupation','$address1','$mobile')";
$r=mysqli_query($link,$q);
if($r)
{
echo "<h3>கஸ்டமர் தகவல் பதிவு செய்யப்பட்டது !</h3>";
}
else
{
echo "<h3>கஸ்டமர் தகவல் பதிவு செய்ய முடியவில்லை  ! மன்னிக்கவும் </h3>";

}

?>



இந்த பதிவு பயன் உள்ளதாக இருக்கும் என நம்புகிறேன் ! நன்றி 



Sunday, 24 June 2018

PHP-How to Display Tamil Fonts in HTML Page?

How to Display Tamil Fonts in HTML Page?


Hi friends, this post for Tamil peoples,  

In normall html does not allow tamil fonts in webpage,  

So our tamil fonts displayed in webpage, just we set meta tag in UTF-8,

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>நண்பர்களுக்கு வணக்கம் </h1>
</body>
</html>



தமிழில் எழுதுங்கள் உங்கள் வலைப்பக்கத்தை  நன்றி !!!!!

PHP- How to find Due dates in PHP and MySQL?

Hi Dear friends,
In This post we see, how to find next due date in easily.

PHP- How to find next due dates in PHP and MySQL?


for example, Finance Management application need to calculated next number due dates, 
Just analysis, what we do?
Step 1: Just given date to add number of days then we get next due date,

for example, 20/06/2018 is given date, 30 days after next First due date then just 30 Days, add next 60 days then we get second due date etc,

In additionally,

Given Loan Date : 20/06/2018
I Due Date : 20/07/2018
II Due Date : 20/08/2018
II Due Date : 20/09/2018

The above example, solved below code, Its very simple logic and easily use to your application.

Loan Date is Current Date then you can use below code


$loandate=date("d/m/Y");

else

You are using HTML5 Date control, then control return default format, so we convert to needed format in below format,

$timestamp = strtotime($loandate);
$lldate = date("d/m/Y", $timestamp);

$duedateinterval=30; // Assign how many date intervals. 1 month then 30, 1 week then 7

$nm=0;
for($i=1;$i<=5;$i++)
{
$nm=$nm+$duedateinterval;
echo $i."Due Date is=".date('d/m/Y', strtotime("+$nm days"));
}


Enjoy! Use code.. If any doubts comments here


PHP- DataAdd methods in PHP?

How to Add to dates in PHP?

Simply example here explain, how to add two dates.

Just assign two dates in two variables

Manual Method

$d1="26/06/2018";
$d2="28/06/2018";
$sec=$d1-$d2; //Its returns in seconds, 
// To convert in Days
$days = $secs / 86400;
echo $days;


Result /Output is

-2 days

Find date difference between given to current date

Runtime Method

$inputdate=$_POST["gdate"]; // Its comes from form, i.e its the given input date
$d1=strtotime($loandate);    // Format to the date
$d2=strtotime(date("Y-m-d")); // Its Current date
$secs = $d1 - $d2;// == return sec in difference
$days = $secs / 86400
echo $days;


Thanks,

Next post we see another issues in PHP







What is AI- Artificial Intelligence - தமிழில்

Artificial Intelligence : Artificial intelligence leverages computers and machines to mimic the problem-solving and decision-making capabili...