Skip to main content

Posts

Showing posts from March, 2013

Get File Extension Using PHP

There are several ways to grab file extension (E.g, 'txt' from 'my.txt') using PHP. You can use anyone from flowing. But I prefer to use pathinfo function, because it is PHP's build in function to grab file path information and others are string functions.

Get Remote File Size Using PHP

We can get a file's size by using PHP build in filesize function. But the problem is this function only works for local file. If you want to get a remote file's size you need to think some other way. In this post I am going to show you how we can get a remote file's size from it's header information with out downloading file. I will show you two example. One, using get_headers function and another using cURL. Using get_headers is very simple  approach  and works for every body. Using cURL is more advance and powerful. You can use any one of these. But I  recommend  to use cURL approach. Here we go..

Generate Random String or Password Using PHP

If you want to generate random numbers, it is possible by using PHP’s rand function. But if you want to generate random string, it is not possible by using rand function. Because rand function only returns numbers as integer between two values.  I coded a simple PHP function that works exactly same as rand function but the deference is it returns string. You can use it in image captcha function, random password generator or anywhere else.

Clean URL Slug From Ugly String Using PHP

Google strongly guide webmasters to make there website URLs SEO friendly or Google friendly. Creating URL from title is the best way to make URLs more user or search engine friendly. This simple function can make clean and friendly URL slug from ugly to uglier title or string.

HTML5 Directory Upload Using PHP

HTML5 allows you to upload a complete directory by using directory attribute. This method is more user friendly than any other file uploading method. We can upload a complete directory at a time using this way. At this time, method is working only in Chrome and webkit browsers by using webkitdirectory attribute we can also add mozdirectory attribute for mozila browser support. Here is a simple example to upload directory using PHP.

Resize Image While Uploading with PHP

On my previous post I was shown an example how to upload file with php and html. It was based on php simple image upload functionality. Today I am going to show you little bit advance of image uploading. Suppose if you run a website and want to allow users to upload image files than you need to think little bit about server's space and bandwidth. For this purpose you need to do some optimization with image files. Image resize while uploading is one of them. All major website do it in the same way. If a user uploads a 5mb image file they resize it in different sizes and store on there server. It helps them to seed up there website and reduce there budget. Now take a look, how we can do it ourself.