In PHP, normally we create PDF using FPDF class by plotting all data against. However, I have found a way through which we can write on existing PDF files.
Export data feature is very useful where the data list need to be saved on the computer for offline used. Export data functionality makes your web application user-friendly and helps the user to maintain list data. Excel is the best format to Export data in a file and you can easily export data to Excel using PHP.
In this tutorial, we’ll show you how to export data to Excel in PHP. Our simple PHP script lets you implement export data to excel functionality. By one click, the user can export data to Excel and download it in a .xls file.
Here is the data array (
$data
) and we will export these data to Excel using PHP.We have created
filterData()
function for filter string provided by the data array.$fileName
variable hold the name of file for download and also content header is defined for download.Now we have run loop through each key/value pair in $data. Using of
$flag
variable we will display column names as first row. array_walk()
is used to filter the data together with filterData()
function.Full script is given below.
If you have any query about this tutorial and scripts, feel free to comment here.
Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request
In this tutorial you'll learn how to upload a file to the remote web server with PHP.
Uploading Files with PHP
In this tutorial we will learn how to upload files on remote server using a Simple HTML form and PHP. You can upload any kind of file like images, videos, ZIP files, Microsoft Office documents, PDFs, as well as executables files and a wide range of other file types.
Step 1: Creating an HTML form to upload the file
The following example will create a simple HTML form that can be used to upload files.
Note: In addition to a file-select field the upload form must use the HTTP post method and must contain an
enctype='multipart/form-data'
attribute. This attribute ensures that the form data is encoded as mulitpart MIME data — which is required for uploading the large quantities of binary data such as image, audio, video, etc.Step 2: Processing the uploaded file
Here's the complete code of our 'upload-manager.php' file. It will store the uploaded file in a 'upload' folder on permanent basis as well as implement some basic security check like file type and file size to ensure that users upload the correct file type and within the allowed limit.
![How How](/uploads/1/2/6/3/126326264/241589183.png)
Note: The above script prevents uploading a file with the same name as an existing file in the same folder. However, if you want to allow this just prepend the file name with a random string or timestamp, like
$filename = time() . '_' . $_FILES['photo']['name'];
You might be wondering what this code was all about. Well, let's go through each part of this example code one by one for a better understanding of this process.
Explanation of Code
Once the form is submitted information about the uploaded file can be accessed via PHP superglobal array called
$_FILES
. For example, our upload form contains a file select field called photo (i.e. name='photo'
), if any user uploaded a file using this field, we can obtains its details like the name, type, size, temporary name or any error occurred while attempting the upload via the $_FILES['photo']
associative array, like this:$_FILES['photo']['name']
— This array value specifies the original name of the file, including the file extension. It doesn't include the file path.$_FILES['photo']['type']
— This array value specifies the MIME type of the file.$_FILES['photo']['size']
— This array value specifies the file size, in bytes.$_FILES['photo']['tmp_name']
— This array value specifies the temporary name including full path that is assigned to the file once it has been uploaded to the server.$_FILES['photo']['error']
— This array value specifies error or status code associated with the file upload, e.g. it will be 0, if there is no error.
The PHP code in the following example will simply display the details of the uploaded file and stores it in a temporary directory on the web server.
Tip: Once a file has been successfully uploaded, it is automatically stored in a temporary directory on the server. To store this file on a permanent basis, you need to move it from the temporary directory to a permanent location using the PHP's
move_uploaded_file()
function.