Category » PHP

How to upload large files in PHP

By default PHP is configured to allow files upload of size upto 2M.

We need to adjust the following PHP configuration directives:

  1. upload_max_filesize: By default this value is 2M. We need to increase it to the maximum size of single file that we want to upload.
  2. post_max_size: It defines the maximum size of POST data that PHP will accept. This value should be greater than ‘upload_max_filesize’.
  3. memory_limit: This sets the amount of memory a PHP script is allowed to use during its execution. Set this to a value greater than ‘post_max_size’ so that PHP script can load and process the uploaded file.

Continue reading »

JSON – An Overview

JSON

JSON stands for JavaScript Object Notation. It is a format for storing and exchanging data. It is based on a subset of the JavaScript Programming Language.

The file type for JSON files is “.json” and MIME type for JSON text is “application/json“.

Here are the characteristics of JSON:

  1. It is a lightweight data-interchange format.
  2. It is easy for humans to understand.
  3. It uses Javascript format but it is a text which makes it is completly language independent as text can be read and parsed by any programmng language.

Continue reading »

Installing “Composer” – Dependency Manager for PHP in Windows

Composer

Composer is a dependency management tool in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

You must have PHP installed in your machine prior to installing “Composer”.

Composer requires PHP 5.3.2 or above (at least 5.3.4 recommended to avoid potential bugs).

Continue reading »

PHP Warning: include(): realpath failed to canonicalize

Warning

I was getting the following warnings when I was running Magento shell scripts from the command line using PHP CLI (PHP Command Line Interface).


PHP Warning:  include(): realpath failed to canonicalize Mage/Core/Model/App.php - bailing in /var/www/magentoproject/lib/Varien/Autoload.php on line 93

PHP Warning:  include(): realpath failed to canonicalize Varien/Event/Collection.php - bailing in /var/www/magentoproject/lib/Varien/Autoload.php on line 93

PHP Warning:  include(): realpath failed to canonicalize Varien/Event/Observer/Collection.php - bailing in /var/www/magentoproject/lib/Varien/Autoload.php on line 93

To remove this warning I started debugging Magento code but no success. Then I googled and came across various posts/forums saying that it was possibly due to APC.

Continue reading »

Cannot add more than 1000 products using Magento admin category management interface

Category Products

Many people having a large catalog have faced a problem in Magento “Catalog Management” that they are not able to  assign more than 1000  products under a category using the Magento admin category management interface.

The category management interface allows you to select as many products as you want.  If you have selected more than 1000 products and then you click on the “Save Category” button, the forms submits without any error displayed on the frontend. But if you see the products actually assigned to category in the grid displayed,  it may happen that all the ones you selected have not been assigned to the category but only the first 1000 selected are.

The issue is logged in Magento bug tracking list – Issue #27321 Can’t save categories with more than 1000 products [http://www.magentocommerce.com/bug-tracking/issue?issue=13203]

Continue reading »

Force Files to Download Instead of Showing Up in the Browser

curl vs wget

Sometimes you may have noticed that when you click on a download link, the file shows up in one browser while in some other browser it gets downloaded. Internet Explorer will usually try to show Microsoft Word files (doc and docx) in the browser, while most other browsers will download it.

If the browser supports a file it shows up the file else it downloads the file. Image files like png, gif, jpg almost always show in the browser. Archive files like zip, tar, and gzip almost are always downloaded.

Continue reading »

Parsing XML file using DOMDocument class

XML is often used as Data Interchange format. I have worked on e-commerce sites that acted as frontend for taking orders and these order were sent in XML format to third party fulfillment system.

Here we are going to parse a XML file using the DOMDocument class.

Continue reading »

Prompting a user to save the data we are sending

In many projects we create reports and we want the data to be exported in csv file so that the user can download it and send it via email to some other department or we need to provide links to some files and want to force the user to download these file. We can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

Continue reading »

Preventing a page from being cached in browser

There are times when we require that a page always get served from the server and not from the browser cache. We can use the HMTL following “META” tags to acheive this.

<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

Continue reading »

Back to top