Posts

Delete a file from upload folder in PHP

Image
  How to delete a file from upload folder   This tutorial teaches you how to delete a file/files from the specific folder using PHP. Sometimes while deleting a record from database table, you also need to delete an image/file from the uploaded folder which is   associated to that record.  For example, if you are removing a product from the table, at the same time, you also need to remove an uploaded product-image. So  For this, In PHP, there is a function called unlink().  Using unlink() function you can  remove a file from the specified folder. Retrieve the product-image from database and pass it to unlink function along with full path.   Syn: unlink ( "path_to_your_upload_directory/" . filename_with_extension. ); ex unlink ( "uploads/" . $ product_image ); Example Code delete_product,php   <?php $ product_id = $_GET [ 'pid' ];     $con  = mysqli_connect ( 'localhost' , 'root' , '' , 'productsdb' );   ...

How to center form using Bootstrap 4

Image
Learn How to center Form using Bootstrap 4       It is common for every designer, while creating a form, to align it in Center. To align Form in center using Bootstrap 4 , there are many ways. Method one  is, you can use bootstrap’s inbuilt classes, or you can create your own CSS class to center align the form. Here in this article, we are going to use an inbuilt class  to center align a form in Bootstrap 4. You can check out the following example. There is an inbuilt class called,  justify-content-center . Just add this class to the form div block, as shown in the given code below.  Method-1 center-form.html <!DOCTYPE html> <html> <head> <title>Coding-zon Demo How to center form in Bootstrap 4</title> <link rel= "stylesheet" href= "https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" > </head> <body> <div class = "container" > <div class = "row justify-content-center"...

Import excel file into mysql in PHP

Image
  Upload Excel file and Import  it into MySQL in PHP  Create a table in some database with given code.   Download Library - extract it, rename the folder to library . Create index.php file with given code in a server. Create excelUpload.php with given code. Create db_config.php . Create one Excel file with some sample data as shown in the below image of Excel file. Create ' uploads ' folder in the same directory. Now start server, run the index.php. Upload a .xls file. If Everything is fine, Excel data inserted in the above created MySQL table - tbl_products . PHP Version:   5.5.11 Folder Structure      Query: CREATE TABLE IF NOT EXISTS `tbl_products` ( `id` int ( 11 ) NOT NULL AUTO_INCREMENT, `productname` varchar ( 100 ) DEFAULT NULL , `description` varchar ( 100 ) DEFAULT NULL , PRIMARY KEY (`id`) )     Top index.php <!DOCTYPE html> <html> <head> <title> coding-zon Demo - Upload Exce...