Category : "PHP"

Php tutorials

Convert html to pdf in php using mpdf

Html to pdf If your php application needs to generate some kind of pdf report then the simplest approach would be to generate the report as an html and then convert it to pdf using some library. Plenty of libraries are available that can convert html to pdf in php. To name a few - fpdf, tcpdf, mpdf etc. I found ...

How to compress images in php using gd

Php applications might need to do some image processing if they are allowing users to upload pictures of somekind. This can include cropping, watermarking, compressing etc. To compress an image the quality needs to be adjusted. Here are few examples function compress_image($src, $dest , $quality) { $info = getimagesize($src); if ($info == 'image/jpeg') { $image = imagecreatefromjpeg($src); } elseif ($info == 'image/gif') { $image = imagecreatefromgif($src); } elseif ...

How to extract tar.gz archives in php

In a previous article we learned how to . Now lets do the reverse, that is extract tar.gz archives and get the files out. The code to extract a tar.gz archive is very simple and uses PharData class. Here is an example // decompress from gz $p = new PharData('files.tar.gz'); $p->decompress(); // creates files.tar // unarchive from the tar $phar = new PharData('files.tar'); $phar->extractTo('new_dir'); The first step ...

How to create tar archives in php

Tar is a common archive format used on linux. Alone it is just an archiving format, that is it can only pack multiple files together but not compress them. When combined with gzip or bzip2 files are compressed as well. Then it becomes a .tar.gz which is actually a gzip compressed tar file. Php has a class called PharData that can ...

How to use proxy with curl in php

Proxy with Curl Curl is a very useful library for transferring data over various protocols like http, ftp, https etc. In other words curl can be used to programatically download a web page, or upload file to ftp etc. It also supports using a proxy. This means that curl requests can go through a proxy server just like a web browser ...

Convert excel to csv in php

When working with data import and export for example, file formats like csv and excel are commonly used. Data can be exported to csv format and imported elsewhere. Also data might be entered manually in an excel file and then imported in the database. So there might be a need to convert excel files to csv format, so that they ...

Generate qrcode and pdf417 barcodes in php with tcpdf

Tcpdf is a pdf creation library for php that is written in pure php and works without the need of any external library. It also has the feature to generate 2d barcodes like qrcode and pdf417. The 2d barcodes can store much more information than the 2d ones like code39 and ISBN. It is recommended to generate barcodes inside pdf so ...

Php – Output content to browser in realtime without buffering

Consider a long running php script that does many tasks and after each task it outputs the status. echo 'Task 1 complete'; .... some delay ... echo 'Task 2 complete'; .... more delay and more tasks ... Now for such scripts it may be important to load the contents in browser as quickly as they are generated so that the user can understand the progress ...

Get the play time and bitrate of an mp3 in php

If your php application is processing media files like mp3, then it might need to find details of the mp3 file like its playtime, bitrate, encoder etc. There is a very useful php library called Getid3 that can extract information from mp3 files. Its written in pure php and does not have any dependencies. Needs php 5.0+. Get it here http://getid3.sourceforge.net/ Here is ...

Php array of iso 3316 country list

Php applications often need to present the user with a list of countries to select his home country from. The iso 3316 country list contains the name of the countries along with the 2 letter codes. Check out the following project on github that contains the uptodate list of the countries in various formats. https://github.com/umpirsky/country-list Here is a sample of the array <?php ...



Connect with us