iGeek Blog

Jignesh Patel's Blog

categories

recent posts

recent comments



Showing posts with label PHP. Show all posts

This is much needed when you want to force the web browser to show the Save File dialog box. Generally the web browser opens the file which can be read by it.

It all depends on the header which is being sent from the web server to the client browser. By default, the browser can open the images i.e. .gif, j.pg, .png & some other file as well like .swf (for FF especially).

This is how it can be implemented with Content-disposition. For example I want to force to save the .swf file.

The PHP code will be:


<?php
header('Content-disposition: attachment; filename=filename.swf');
header('Content-type:application/x-shockwave-flash');
readfile('pathoffile/filename.swf');
exit;
?>

I was facing the issue: Emails were not getting sent after someone add the comment on the post in my wordpress based blog, http://magentocoder.jigneshpatel.co.in/

The problem was not in the Wordpress, it was on the hosting server. on which the blog is hosted.

After posting Ticket regarding the problem, they replied simple php mail() function won't work on that. As they are having the security concerns. After requesting them, they provide me the sample php code, which can send the email.

Here are the steps to be followed if you want to fix the email not sending problem (it will work if your problem is similar to mine).

1. Download the 'class-phpmailer.php' from here
2. Replace it with the existing file inside the wp-includes directory. (Make sure you have taken the backup of older one)
3. Then open the file 'pluggable.php' from 'wp-includes' directory
Find the line
$phpmailer->IsMail();

Replace it with
$phpmailer->IsSMTP();

You may need to setup the email account on the hosting server. Like 'wordpress@hostname.com'

I did up to these much changes & emails started to be sent successfully.

I feel jealous when someone proudly so say it.. "I'm sitting next to ZCE!", because I am not that much lucky. However I am sitting somewhat nearer to ZCE.

Well, The ZCE is Anil, my friend at my life and my TL at my work place. And the person sitting next to him is Hitesh. Anil became the ZCE last week, its proud for me and the same should be for the PHP cum Web Developers from Gujarat. He is just a second person from Gujarat to be a ZCE, his roommate also achieved the same on the same day. So now we have three Gujju ZCE.

I have seen Anil's hard-work and dedication to become the ZCE from last year. He really deserve it. Nothing more I can say. Congrates Dude...

Its simple and sober to assign value to a variable in Smarty. However assign an array to a variable in .tpl file is not simply available. You can create ab array in PHP and assign it to the variable to be used in smarty template, but its on PHP side.

But what if you want to do something like this ?

{assign var=$col_width value=array('2%','10%','17%','13%','20%','10%','19%')}

No, we cant do that. For doing the same thing you have to put a compiler.set.php file inside smarty directory. Can be downloaded from here : http://smarty.incutio.com/?page=set
Put it here: smarty/libs/plugins

To create array use the syntax below:

{set var=$col_width value=array('2%','10%','17%','13%','20%','10%','19%')}

There are many tools & scripts providing exporting MySQL Data to Excel files.
But when it comes to export only database tables structure, in other words design, at least I failed in finding such tools or scripts.

As a developer, I always need to provide DB Structures along with all table names with their fields & types as well. So I have to make the .xls file for that manually. So we know that, every project will require those things. Sometimes its pathetic when we have large no. of tables.

As a solution, I made a web based tool or say script, which can be used to export MySQL DB Stucture to .xls file. I named it "Export MySQL DB Structure to Excel" .

First release on sourceforge.net can be download from the link below:

https://sourceforge.net/project/showfiles.php?group_id=236953

So many Firefox extensions are doing the same thing which I have just made. And its about downloading YouTube videos.
I made a PHP script to download YouTube videos. Thanks to Open Source Communities, from which I taken some part of script. I just implemented it on the site below.



Visit : YouTube Video Downloader

Just enter the YoutTube video URL as mentioned there.
By default you will be prompted to save video with name 'get_video' with no file type specified. Just change the file name to 'get_video.flv' to save it as flv file.

I found a PHP code sample that somebody had written as following line of code:


   1: <?php
   2: System.out.print($result);
   3: ?>

What you say about that code ?
This actually works in php. It will not print anything, but It doesn;y produce any error.
It just sees them as constants which do not exist and are interpreted as strings, and apparently, this is a valid PHP statement as well:

   1: <?php
   2: "this"."is"."a"."string";
   3: ?>

My friend Jignesh Thummar forwarded me a link of Presentation on 'Getting Rich with PHP 5' by Rasmus Lerdorf, the founder of PHP at O'Reilly's Open Source conference.

The Slides available online here.