PHP – Copying x Files to n Folders

So a co-worker needed to find a way of coping a few files (10 files) to a bunch of folders if the files weren’t already present. Instead of doing a manual copy paste in Windows I created this code to do the above. If anyone needs to do something similar feel free to use this code. Pretty much all is does is create an array with all the folders where this PHP file is being run (this is the root where the bunch of folders reside). Then it creates another array of files – these are the files that we need to copy to all the folders. This array is created by looking in the templates folder and adding each file to the array.

The ‘foldersOnly’ function gets the array from scandir() and cleans it up. It removes the ‘.’, ‘..’, and a couple Dreamweaver folders like ‘_notes’ and another one I can remember. The new array returns only the folders we want to work with. The ‘filesOnly’ gets the array from the PHP function scandir() and returns only the files in that folder. Once we have our arrays we are ready to start.

We are going to loop for each folder and inside each folder look for each file. We check to see if the file is in the folder, if so we do nothing. If the file is not there, we copy it from the templates folder. This is pretty much it, once all the loops are done every folder should have the missing files. The code is below: Continue reading “PHP – Copying x Files to n Folders”

Quick update to Uploader – fixed some minor bugs

Two bugs were found and addressed. The first bug happened while trying to upload a link. I dropped a URL on the Uploader and the app got stuck in the “Thinking” phase. After some troubleshooting, I noticed the page for the URL did not have a <title> tag so the app was sending the PHP page an empty ‘name’ variable causing the PHP page to stop executing during the validation phase.  The fix was to assign a default name to the link if no title tag is present. In these cases, I’ll manually give the link a proper title.

The second issue also had to do with the <title> tag. In this case, the HTML did have a title tag but the case was different that what I was looking for. My code was looking for all lowercase characters and the tag in the HTML was in uppercase. My first thought was to do a .toLowerCase() on the HTML code but then all the titles would be in lower case and wouldn’t look as presentable (ex: the size of our planet vs The Size of Our Planet). After giving this some more thought, it seemed using regex would be the cleanest solution. A quick Google search returned this page which said by adding an ‘i’ to the end of my regex, the search would be case insensitive. I gave it a try and it worked like a charm.

Before Code:

var start:Number = s.indexOf('<title>');
var end:Number = s.indexOf('</title>');
var title:String = s.substr(start + 7, end - start - 7);

After Code:

var start:Number = s.search(/<title>/i);
var end:Number = s.search(/<\/title>/i);
var title:String = s.substr(start + 7, end - start - 7);

Uploader Phase 2 complete!

Here is a screen shot of the Uploader 0.1.0
Uploader 0.2.0

So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this image, and update the WordPress database with information about the new image. The new image would then show up the next time a person visits my blog. If you notice, there is now a “Pics of Interest” section on the sidebar to the right of the page (similar to what people are doing with the flickr plugin). Every time I drag an image URL into the Uploader, the new image thumbnail will show in that area and if you click on the thumbnail you’ll see the full size image.

It was actually much easier than I originally thought to make this work. Technically, the Uploader already has the drag/drop functionality and already takes in a URL. The only extra AS3 code was a check to see if the URL was an image and if so call the PHP page with a code (I’m passing –@IMAGE@– to know it’s an image – it was just the first thing that came to my head) so then PHP knows this URL should be treated as an image not just a URL. If you remember, phase 1 for the Uploader allows a person to drag/drop a URL into the app so it creates a new link under the “Links of Interest”. Continue reading “Uploader Phase 2 complete!”

Car problems fixed, new tune results!

So I recently made a post about the issues I’ve been experiencing with my car for the last couple weeks. Well I’m happy to say everything has finally been taken care off and my car is better than ever. Scott Siegel did an amayzing job last night on my car as always and here are the results: Continue reading “Car problems fixed, new tune results!”

CarLab X-Brace Review – 05 STI

After spending plenty money on go fast mods I decided it’s time to spend some money on making my car handle better. It seems most people tend to start with sway bars, struts, or springs so I started looking into those a bit more. After giving these options some thought, I decided sway bars would be the better choice since they aren’t too expensive and would be an easy install. I went to the ‘for sale’ forums at IWSTI looking for some sway bars and noticed a group buy for the CarLab X-Brace.

I didn’t know much about the x-brace but when I clicked on the thread I saw lots of very positive comments about this brace. I did a site search for the x-brace and even more info came up on how wonderful this mod is and some people were saying this was the perfect first suspension mod for them. The price was about the same as getting both front and rear sway bars and it sounded like I would get more benefit from the brace so I decided to join the group buy and bought the brace. Continue reading “CarLab X-Brace Review – 05 STI”

I guess having some car problems after 4 years is normal…

So I’ve been driving my car around without any big problems for the last four years. Right now I’m at 32,000 miles – bought the car brand new. The first 10k I was running on stage 2 and the last 20ish k I’ve been running at 450whp with the turbo upgrade. The only things I’ve done are regular oil changes (always synthetic), new spark plugs a few times, and… changed my tires at 22k and that’s it. Stock engine, stock clutch, stock brakes/pads.

Four weeks ago I went on a mountain pass with a few people and had a blast. Unfortunately half way through the pass my car started acting up. I floored it like I had been all morning and then my car cut gas around 5k rpm and my check engine light turned on. Someone had a code scanner so we tried to read the code and nothing was coming back. The guy then reset the code (since there was none) and the check engine light turned off. I decided to try giving the car gas one more time to make sure it wasn’t just one isolated random incident and it wasn’t. Same thing happened and my check engine light came up. Continue reading “I guess having some car problems after 4 years is normal…”

Atlanta PHP User Group – 11/06/2008

So I attended my first Atlanta PHP user group thanks to Moses nagging me about going :p. I’m glad I went, I had a great time. I really enjoyed being there listening and even sharing a little. The things I took with me that I’m going to mention are:

Atlanta Startup Weekend
During the meeting I found out about this really neat event. The objective of the Atlanta Startup Weekend is to get a bunch of people together, divide them into groups (developers, marketing people, business people, etc) and in one weekend finalize a product from a concept. Tickets are already sold out so I’ll have to try for next year. I’m sure I could learn a lot.

PHP Wiki
I didn’t know about this page: http://wiki.php.net/. You can get lots of neat information from the PHP group. The rfc (request for comments) section is also very informative. You can see what requests have been made, which request are going to be implemented and which have already been implemented. It’s a good way to stay ahead of the curve since you would know what’s coming out before it’s out.

REST
Don’t quote me on any of this, this is just bits and pieces that I think I gathered from listening to others talk. If I understand correctly, REST is a standard for creating RESTful url/url/web services that are efficient and scalable… maybe? I heard REST mentioned a lot during the <head> conference a couple weekends ago and I heard it mentioned a few times last night during this meeting. So, now I need to go do some more research and figure out what this REST thing is all about. Seems like it’s something worth knowing about and maybe even following? If you have any info or resources you can recommend please do.

Joey’s WordPress Setup

I’m going to list the changes I’ve made to WordPress to look and function the way it is today. This will probably change over time, but I feel as if it’s working pretty well right now. This information is for anyone trying to create something similar and for me to use as reference later if I need to recreate this again.

The theme I’m using is Devart by deniart. The few mods I’ve made to this theme are:

  • Edited the /wp-content/themes/devart/images/author.gif (to show my pic instead of the default apple)
  • Modified the /wp-content/themes/devart/style.css to change the way <code>, <ul>, <li> look
  • Modified the style.css to add my twitter logo and link on the top right hand side of the page
  • Modified the header.php page to add my twitter logo and link to the top right hand side of the page
  • Had to add <?php wp_footer(); ?> to footer.php to launch stats code
  • Added img#wpstats{display:none} to style.css to hide the 🙂 from stats plugin

I’ve also done the following to my setup:

05 WRX STi – Road to 450whp Part 2 (300whp to 450whp)

300 whp was fun but like I mentioned in Part 1, there were some issues that I was not happy with.  After spending countless hours at IWSTI (where I do most of my research about my car), I decided 300whp just wasn’t enough. I wanted to play with the big boys… I wanetd more power… I wanted a bigger turbo. This is where TopSpeed comes in.

I called Tray up at TopSpeed and told him I wanted more power and what he recommends.  His question was simple, how much power do I want and I answered 400whp.  The FP20g wouldn’t get me there, green would be closer, but his recommendation for my needs and budget was the FPRed.  He listed a whole bunch of things that need to be changed in the car for this turbo, told me the price, and I gave him the OK to proceed with the project.

Continue reading “05 WRX STi – Road to 450whp Part 2 (300whp to 450whp)”