Sunday, November 8, 2009

Flash caching PHP response

Recently I ran into an issue where I would call a PHP file that would generate a unique id and return that to Flash (I am sure I could do the same thing from within flash but decided to just use PHP's uniqid to solve this for now) The id that comes back is used for files the user is uploading. The problem I noticed is that Flash would make the call to the PHP file and then get back the same UUID everytime. I thought that perhaps Flash was caching the page and then just loading it instead of re-requesting it from the web server. In summary this was somewhat true. The page was being cached somewhere and needed some PHP header references to prevent from caching properly.

Flash kept loading the same values from a PHP script that should have been generating different values on every call.

I included these header functions and parameters at the top of my PHP file.
header( "Pragma: no-cache" );

header( "Cache-Control: no-cache" );

header( "Expires: Sat, 01 Jan 2000 00:00:00 GMT" );

 Happy programming.

Getting file extension with ActionScript

It has been some time since I have posted, but I figured this one quick function for extracting a file extension was worth a quick post.

You are dealing with files and want a quick way to extract the files extension.

A simple function that will return back you to the extension of any file with or without a full path reference preceding it is this:
function getFileExtention(str:String):String{
    return str.substring(str.lastIndexOf(".") + 1, str.length);
NOTE: This will not account for URLs that have GET parameters on the end of them. To do this, Google search getting file extension using regexp or regular expressions.

 I hope this helps someone who is looking for a quick solution online. Good luck.

Sunday, August 2, 2009

Symfony and XAMPP httpd.conf file issues

Here is another short simple post of something I had to figure out and could not find documented anywhere.

Problem: When install the Symfony MVC on my localhost (Windows Vista), I would copy-paste the additional httpd.conf settings to the httpd.conf file in the xampp folder. When I would restart Xampp (or apache more specifically) I would get a windows error telling me that Apache had failed to start properly.

Solution: Although I had switched the paths to be specific to windows, I did not know until reading documentation later that the apache still requires all backslashes to be forward slashes in the file paths.

Simple mistakes, but now solved.

Monday, July 20, 2009

build.xml does not exist! - Apache Ant

Problem: When trying to run a command with ant after installation, you might see this error:
Buildfile: build.xml does not exist!
Build failed

Solution/Explanation: This message is showing you that ant works and that it is looking for your project file. The documentation by Apache gives this explanation:
You can check the basic installation with opening a new shell and typing ant. You should get a message like this
Buildfile: build.xml does not exist!
Build failed
So Ant works. This message is there because you need to write an individual build file for your project. With a ant -version you should get an output like
Apache Ant version 1.7.0 compiled on December 13 2006
You can see that this is not really an error but just a notification.

Friday, July 10, 2009

Linux Permission Made Easy

When learning Linux, sometimes people have a tough time understanding how folder/file/application permissions work. I am writing this to show you a quick easy way to figure out which permissions to use.

Folder/file permissions on Linux can be difficult to understand. Sometimes you will see 0775 or 735 or if you are looking at files in Linux (using ll or similar command) you will see something like -rw-rw-r--.

Solution: Figuring out what these mean is easy, you just need to perform two steps and you can have permissions the way you want in no time. Also, keep in mind that the 0775 is basically the same as 735, the leading zero on the second has been removed and is not displayed in this report. For the purposes of this post, we are going to ignore the leading zero. Let's look real quick how 0775 (or 735) and the display of "-rw-rw-r--" relate.

Understanding how we got the 7
The second number of 0775 is actually made of from this simple chart by adding which permissions you want enabled:
4 : Read
2 : Write
1 : Execute
0 : None

These four options are compined in various ways to give you exactly the permission you want for each digit in the full sequence of 0775. The second number has all the permissions ( 4+ 2 + 1 = 7) meaning it can be read, written, and executed (if executable). Like wise, setting this to read and write only, would equal the number 6.

So, now understand the full sequence as it applied to the file/folder/application
The numbers representing the our demo sequence of 0775 have been charted to show what each one represents.
0 : Reserved (we not discussed this in this tutorial)
7 : User (the permissions of the user)
7 : Group (groups made in Linux, this could be staff, etc.)
5 : World (the permissions the rest of the world [or in our case, operating system users/guests])

Now let's look at how 0775 and -rw-rw-r-- relate
You may have already guessed it, but here it goes. You will notice there are 3 main permissions (read, write, execute). The first letter in the sequence -rw-rw-r-- is that one that we don't talk about in this tutorial, the leading zero in 0775. The next three letters or hyphens (rw-), make up the read, write, and execute permissions for the user group. The following 3 after that make up the permissions for the Group. And the last 3 represent the world permissions.

Now you hopefully have an idea of how to read, understand, and how to set up your own permissions.

Disclaimer: At the time of writing this, I am new to some things Linux and am bound to get things wrong. If I have listed something incorrectly, please let me know so I can change it and provide good reliable information. Thanks.

Thursday, July 2, 2009

Windows Bug - Exabytes of Temporary Internet Files

It recently came to my attention when performing a Disk Cleanup, that Windows has begun telling me I have 4.70 EB (fyi 1 Exabyte = 1073741824 GB, I guarantee my laptop only has 120 GB max). When I went to search this out online, I didn't find much online except one other guy's forum posting. I decided to create this post and report on what I find. Looking closer into my temp i-files, the largest file I found, was a 350 MB Photoshop file.

It seems that somehow, one of my files is causing Vista to report incorrectly on space. After running Disk Cleanup Utility, this problem still existed.

I decided to try using Glary Utilities, some great personal tools for computer maintenance and management.

Although, these tools are great and cleared out another couple GBs of wasted space, the problem still exits. I am guessing I will have to do a post later to follow up on this situation. Good luck to anyone looking for a solution, and if you find one, please post me a comment about it. Thanks.

Well it looks like my computer needed a restart.

Native Screenshot of Application in Windows Trick

I learned about this at work and thought it was really cool and figured I would put it on my blog.

If you are like me, sometimes you want to take screen shots of just one window or application (instead of 3+ screens as I know some of the people have).

The normal screenshot is done using the Print Screen button on your keyboard, sometimes on laptops, etc. the button will read "Prt Scr".

When you hit this button and paste it into a graphics program, it will place a screenshot of your entire desktop(s).

Normal Print Screen takes a picture of the screen and not the application or window in focus. If you have to open a editing program and go cropping the image, it just isn't any fun.

You hold down the Alt key when you hit Print Screen or Prt Sc.

Hope this is useful and saves you time without having to get a program just for cropping or screenshots (plus there is a tool built into Vista to help with this called Snipping Tool)

Thursday, June 25, 2009

The IE Input Image Catch

While working hard at my work (which is why this post is short), I was creating a site that used image inputs. All was well and good when running it in FireFox, but in Internet Explorer, it was a different story.

Checking for the input name in the POST variable when using an image type, the PHP looking for the name could not find that input object.

Internet Explorer as well as some other browsers, pass the x and y of the image you used for submitting your form instead of the input name. To detect these with PHP, you can check for

isset($_POST['image_x']) || isset($_POST['image'])

if either is true, you can continue to process. You may also note that the browser has converted what would have been image.x into image_x. The period character is swapped out.

Now you should be able to have your input be detected in all major browsers.

Monday, June 8, 2009

Mounting CDROM on Linux

Since I have used Linux for only a short while, I am not familiar to everything CLI (command line interface) and all the commands. When mounting a CDROM disc in CentOS 5.3, I found that all the forums didn't seem to help with the issue I was having. After some time, the answer was simple and I decided to post it here for anyone else who might be having the same issue.

Mounting a CDROM in Linux from command-line.

After several various attempts and ensuring I was root (sudo user) I was finally able to figure it out. My first error was that I did not add the type for what I was trying to add (in my case I wanted to run a program from the CDROM, if you are trying to play music, you do not need to mount your CDROM disc this same way, just open your music app and go). After looking up that the type for cds is 'iso9660'. I next ran into an error where my mount point did not exist, (in my case I was using the mount command ' mount -t auto /dev/cdrom /mnt/cdrom ').

I went to my mnt directory and mkdir the folder cdrom.

When I ran my mount command again, it mounted the cdrom is read-only mode and worked.

The solution of creating a mount point (folder) was simple enough but difficult since no one seemed to say it. I hope this helps you.

Monday, March 2, 2009

Perl Unlink Files on Windows

While working on a lab for one of my classes, I was writing a cgi script in Perl to manage log files for the web admin of a web site. I feel new to all things Perl and so debugging problems seems to take some time. TA's aren't much of a help and documentation online for my specific problem seemed scarce (it doesn't help when your not sure what the problem is).

The Problem:
The following script would not unlink files in the directory


use strict;

my $url = "C:/xampp/htdocs/website/admin/logs";
my (@files);
opendir(DIR, $url);
@files = readdir(DIR);

print "Content-type: text/html\n\n";
my $file;
foreach $file (@files){
unlink $file;


The Solution:
It seems that the $file variable doesn't actually point to the file but has a reference to the name of the file. For a while I kept thinking it had something to do with using unlink in Windows or file permissions. Through testing various things and getting some things to work, I found that by including the full path to the file when unlinking the files fixed my problem. My ending perl script looked like this:


use strict;

my $url = "C:/xampp/htdocs/website/admin/logs";
my (@files);
opendir(DIR, $url);
@files = readdir(DIR);

print "Content-type: text/html\n\n";
my $file;
foreach $file (@files){
unlink $url . '/' . $file;

Hopefully this post will save someone else time. Please let me know if this worked for you or the questions / comments you have. Thanks.

This site gave me some good ideas that helped me figure out the solution.

Saturday, January 31, 2009

Komodo Debugging Options Window

I decided to write a small post on this, this it has bothered me since I installed Komodo 5.

I had written a perl script and was trying to execute it, but every time I did, the Komodo IDE would pop up a Debugging Options window. I am new to both Perl and Komodo, so I didn't feel I had any use for debugging arguments and when I closed the window, Komodo would stop executing my script.

It turns out the fix is simple. In Komodo you go to the main menu at the top of the IDE, choose -> Edit -> Preferences... At this point the preferences windows is displayed. Now choose Debugging from the Category list on the left, then check the checkbox on the right that says "Skip debugging options dialog (use Ctrl key to override)".

That should do it. Other people have had different problems, and unfortunatly I can only blog about the ones I run into.

Monday, January 12, 2009

Installing Ubuntu 8.04 on External Hard Drive

For my IT class, we were told to get an external hard drive and install Ubuntu 8.04 (8.10 has known issues with Samba Authentication). Since I am new to the Linux world (I can get around and program on CLI, just have had not much knowledge as far as installation and GRUB. The install was from the Ubuntu Live CD and I installed like normal but made sure to only format and install on my External Drive (Western Digital 320g). I included GRUB boot loader on install screen 7 under the Advanced options and made sure to install it to my external as well. When restarting my computer to boot from USB, it wouldn't load the GRUB menu from my external, it just went to my normal computer's boot process. When examining the Bios, I ensured that the boot order for my machine had USB as the first option in the list. What I failed to notice and would have saved me a lot of time in the beginning was that I didn't go into the Advanced Bios options and set the Bios to look for USB devices on boot. After this was enabled, I got all sorts of errors. Finally, when surfing the net for answers, I found with an article saying that the external hard drive is acting as primary and so the Grub boot loader should look for it on hd(0,0) and not what it installed as (i.e. hd(1,0)). When editing the GRUB boot entries to look for hd(0,0), the external hard drive booted properly.

Please forgive my lack of formatting, I don't have much time to write this entry. 

Good luck.