Discussions about PHP, jQuery, SEO & general web development

finalwebsites.com Blog

This section is the place where we provide limited support for the scripts and tutorials published in our network. While our Web Development Blog is mostly used to publish tutorials, reviews and articles, is this section also the place to post PHP code snippets en script release information. This blog is the successor of the PHP forum we used in the past.

Latest posts and discussions

Upload Class and Mime Type problem (IE7 only)

2012/02/06

Latest version does not work with IE 7 (only checked this version).
MIME type for some .jpg files are reported by IE as image/pjpeg so validateMimeType fails.Running the test on same machine with Mozilla works fine.

The script / class file_upload does not support multiple MIME types for same file extension.

It seems that when uploading IE is getting the MIME type from file content using FindMimeFromData, and that returns image/pjpegfor standard MIME type image/jpeg you can see this in this MS article:

http://msdn.microsoft.com/en-us/library/ie/ms775147(v=vs.85).aspx

I suggest that if possible your script addresses this issue.

Alex

Create a random post button for WordPress

2012/02/05

If you like to get more page views per visitor on your WordPress site or blog you should try a random post button. People like to get surprised on what the next page will show them. The whole idea of StumbleUpon is based on random web pages, every time you click their stumble button you get a new random article, image or video.

The following code will select a random article and shows the link together with a graphical button on your site.
Read more »

PHP download files bigger than 700MB

2012/02/02

Today I got this question from Armin:

Hello Olaf!
I have a question for you regarding your php file download script!

I am using it on my band’s website for distributing our DVDs and music to our fans. Though I have found a problem affecting only Internet Explorer users downloading large files (the file in question is 700+MB). It seems to download only a fraction of the file, like ~half.

Any idea about what exactly is causing this issue? Any help would be greatly appreciated. :) Read more »

Shorten text values

2012/02/02

I’m using this function on almost all my websites:

function create_short_version($text, $len = 150) {
	$parts = explode(' ', $text);
	$ic = count($parts);
	$txt = '';
	for ($i = 0; $i < $ic; $i++) {
		$txt .= $parts[$i].' ';
		if (strlen($txt) >= $len) break;
	}
	$txt = trim($txt).'...';
	return $txt;
}

The function works like the sub_str() function in PHP, but without to break words in pieces.

Attachment Mailer – pdf files and the $type argument

2012/01/06

First, I want to thank you profusely for this class. I hope now that I won’t ever have to construct an email header manually again. Here’s my question -

When I attach a pdf file and explicitly set the ‘$type’ argument to “application/pdf” it arrives corrupted. When I just do it the easy way, like this – $mailer->add_attach_file($savepath), it comes through with no problems. I don’t mind having to type less, but is there a reason for this that I should be aware of if I’m trying to attach other types of files?

Steve Morse