Showing posts from 2012

Open file selection box when click a link or an image

Sometimes you will meet requirements like this:

I want someone to click on a link/an image and the file selection box will open immediately.  Then user can upload an image through AJAX.  (Think Facebook cover photo upload)

At first, it seems that it is easy.  Here is what I did:

<input type="file" id="file1" name="file1" style="display:none;" />
<a href="javascript:;" onclick="$('#file1').click()">Some link text</a>

It seems perfect when you combined it with jQuery upload.  But I was wrong.  As of this writing, the above lines work in FF v.17 and Chrome v.23, but it does not work in IE9.  It will prompt:

SCRIPT5: Access is denied
It is definitely NOT cross domain problem.  It turns out that it is a bug in IE (Original link).

So, how to solve this: The answer is quite counter-intuitive.  Here are the steps to do so:

Create an <input type="file" /> tag, but this time, do not use display:n…

How to display HTML in Blogspot/Blogger, without converting HTML?

Certain bloggers (like BlogKori and Gordon's Blog) claims that, in order to show HTML in blogspot/, they need to first convert their HTML code to entities, then paste them back to blogger.

I found that this is not the best method.  Actually inside blogger, there is an option that allow you to paste HTML directly without converting.  Here is how:

While you are editing, on the right hand side there is a list of options:

Click Options, and you will be presented with a list of options:

The original option is "Interpret typed HTML", select "Show HTML literally" and "Done".

Then paste your HTML directly and see preview, you should be able to see the HTML nicely.

By the way, the font-size in your pasted HTML may be very big, you can simply resize it to "smallest" to show it more nicely.

PHP Paypal SOAP SetExpressCheckout Request Message Example

This Paypal SOAP API operation page and this Paypal SOAP API Basic page are developed by in order to tell us how to use SetExpressCheckOut Request message in SOAP way.

However, the page does not tell us "EXACTLY HOW" to write the XML because they do not provide any exact example on how to format the XML (It only mention a little bit in the soap api basic page, but I get little value from reading this...).

I personally think that this document is badly written, because you still don't know how to get start by reading that.  Therefore, I test a lot of things in this poorly written documentation, and supplement it by an example here.

If you want to find out how do you format your XML correctly, here is the example.

AttentionThis example DOES NOT CONTAIN ALL options.  It covers around 60 - 70% options in the page.  But you should be comfortable on how to make use of that Paypal documentation easily.If you define a list of items in XML, but it does not display in p…

PHP file upload data not post

If you use the normal PHP POST file upload method mentioned in official PHP page, chances are you may get empty $_POST or $_FILES array.

In my case, I am creating a page that allow people to upload a CSV file (can be a very large file, e.g. >10M), then everything is following what is mentioned in the official PHP page.  However, the $_POST and $_FILES do not have any data when I print_r() it.

Probably it is the main reason: your upload file size is too big, a.k.a: Size matters.

Here are some suggestions:

1. Make your MAX_FILE_SIZE bigger:

<input type="hidden" name="MAX_FILE_SIZE" value="9000000000" />
2. In your PHP code, add this:
ini_set('upload_max_filesize', '128M'); ini_set('post_max_size', '128M'); If it does not work, add these in your php.ini file instead of inside your PHP code.
post_max_size = 128M
upload_max_filesize = 128M 
Hope it helps someone, and for my reference.

PHP error_reporting exclude notice and deprecated

For information to anyone who want to exclude more than one option of error_reporting in PHP, use this:


Use () and | to pick errors that you DON'T want to show.