Monday, December 22, 2008

Making a Link Select a Select Box in Javascript

I needed to have a link select an option within a selectbox.  What I wanted to do was have a bunch of links out there and if a user clicks one, move down the page and have a value in my selectbox already selected according to that link.

I found a solution online that worked great.  It uses javascript, but works wonderfully.

Since blogger doesn't let me paste code easily, I'll just direct you to the link.  If it ends up being dead in the future, please leave a comment and I'll post the code.



Tuesday, December 16, 2008

Server Root Path with PHP

Here is a simple way to get the server root path with PHP:

$_SERVER['DOCUMENT_ROOT']

Say you want to check if a file exists, you could do this:

file_exists($_SERVER['DOCUMENT_ROOT']."/yourfolder/yourfile.extension")

Putting this in an IF statement will see if the file exists.  If it does, file_exists will return true, else it will return false.

Friday, December 5, 2008

Trim Whitespace in PHP

Trim is a nice built-in function for PHP.  My default it will trim off the whitespace from the beginning and end of a string.

Description

string trim ( string $str [, string $charlist ] )

This function returns a string with whitespace stripped from the beginning and end of str . Without the second parameter, trim() will strip these characters:

  • " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.      

Returning Content to PHP Variable with cURL

I have a few examples of using cURL here in PHP but this parameter allows you to store the content of the selected source to a PHP variable.

Say, for example, you are loading up a page with cURL and want that information store in a PHP variable to use throughout your site.  You can do this by adding the following code to your cURL request:

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); // return the page content

So here is a full block of code:

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'URL_TO_THE_PAGE');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$savedvalue = curl_exec($curl_handle);
curl_close($curl_handle);

In this case, $savedvalue will hold all the information returned by that page request.

cURL is very powerful and worth learning about.  Here is a good resource: PHP login/download file - CURL libraries.

Thursday, December 4, 2008

PHP Header Redirect

Most people may already know this but for some reason I always forget the syntax (I know... its simple...).  So here is how you can redirect to a page with PHP.

Remember: You have to redirect BEFORE loading any HTML tags or header information.  This should always be tested before ANY echo/print tags or any output.

header('Location: http://www.example.com/');
exit;

Don't forget the exit, this prevents the rest of the page from loading and possibly stopping your redirect.

Tuesday, December 2, 2008

Flash Multiply Error

Flash PNG or any image Multiply Filter error.

I am having trouble with the "multiply filter" in Flash. Evidently, I am not the only one.

Someday, I hope to find an answer.


Here's a guy who posted the SAME issue:
http://www.bitsofstring.org/extra/flash/flashblendingtest.html

Saturday, November 22, 2008

FireFox scollbar ... always there?

Tired of seeing the site jump back and forth from "non-scrolling" pages to scrolling pages? Throw this in your CSS:

html {
overflow: -moz-scrollbars-vertical;
}

Now there is always a vertical scroll bar (even "grayed out") present and the site stays in position. No more kitters. No more wondering if the CSS code is correct or did something change...

Done!

Friday, November 21, 2008

IE6 margin fix

CSS and IE6 Margin Fix on float!

When floating a < div > in Internet Explorer 6 and any kind of a margin ... it doubles the amount ... of course it does. That is exactly what IE6 should do. Especially since FireFox, and all the others actually set the margin to the number specified.

This guy posted the fix... it's pretty simple. Just add "display:inline" to the CSS attribute.

http://www.positioniseverything.net/explorer/doubled-margin.html

Matt Crigger
http://www.phirebranding.com

Thursday, November 20, 2008

Escape Character in MSSQL

I had a frustrating time trying to escape single quotes in MSSQL.  I had enclosed my content in single quotes so that double quotes would be okay, but then I had to deal with if a user put a single quote in the field.  In standard MySQL you could just use the backslash (\) but MSSQL requires a single quote (') in order to escape a character!

Here is a little function I made in PHP to look for single quotes and doubling them so that they would be escaped (thus allowing the content to be inserted into MSSQL).

//********************************
// fix quotes for mssql
//********************************
function mssql_quote_fix($text)
{
$text = str_replace("'", "''", $text);
return $text;
}

Just call this function on the text you're trying to insert.

I'll give a little credit to this article for helping me: Escape Character In Microsoft SQL Server 2000

Wednesday, November 19, 2008

cURL Alternative to PHP Include (with SESSIONs)

This is followup to my previous post about cURL Alernative to PHP Include.  Basically, the method I posted before didn't copy over the current $_SESSION in PHP to the page that you were calling.  This mean, that page didn't know the session (i.e. if someone was logged in).

The following code over comes this problem and passes along PHP's $_SESSION information to the called page.  This has been tested for pages on the same server, I'm not sure how it will work if calling a page from another server.

<!-- save $_SESSION to use in call -->
session_start();
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
session_write_close();

<!-- Begin cURL call-->
$curl_handle = curl_init('enter_external_url_here');
curl_setopt( $curl_handle, CURLOPT_COOKIE, $strCookie );
curl_exec($curl_handle);
curl_close($curl_handle);

Tuesday, November 18, 2008

cURL Alternative to PHP Include

cURL is usually installed with PHP on a server.  I ran into a problem where I needed to be able to include external URLs into a website.  The server I was using didn't allow for urls in the include field (allow_url_include was off).  So, I used this bit of code to do the same thing:

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'enter_external_url_here');
curl_exec($curl_handle);
curl_close($curl_handle);

Make sure to replace enter_external_url_here with the actual URL.  Quotes are required around the URL.

Friday, November 14, 2008

Simple Javascript Object Check

Alright this is something fairly simple but it is useful when you want to have javascript check if an object exists before trying to manipulate it.  As we should know, javascript will die if you try to do an action on an object that doesn't exist.  This is part of the simplicity and low-weight of javascript that makes it great for the web.

So before you try to do anything to an object that might not exist on a particular page, put in the following line of code:

if (document.getElementById('the_id_of_the_object') != undefined)
{
     //code goes here
}

Again, something super simple but may save you some problems in you're building a larger site with pages that might not have the same objects but share the same scripts.

Thursday, November 13, 2008

When Tables are Okay

The trend in web development/design is to work with CSS to create layouts.  In the past we used tables to structure websites, this was mainly because of their easy, the lack of development of CSS, and the lack of CSS standard compliance in web browsers.  There are times when tables are applicable even though there is a certain stigma to using them nowadays.

I found the following article very useful in helping to figure out when tables are a good choice and should be used.  If you're interested, take a read: Tables for Tabular Data - What is Tabular Data?

Tuesday, November 11, 2008

EM Conversions for Base Font of 12px

In order to make things really easy, I made this little table to help with conversions from pixels to EMs.  I'm used to using pixels and I'm sure most everyone is, so here is something simple.

The following table applies to a browser that is set to 'medium' font-size (the standard).  Since most websites use a standard 12px font for text, I set the body font to this value so that the EMs are pegged at 12px (i.e. 1em = 12px).

Base (from browser): 16px;
Body (CSS): 75% (12px);

Befor getting to the conversions, take a look at the above values.  You'll need to set your BODY tag to font-size: 75%.  75% of 16px is 12px, this is what we want to work with or else the table below will not work.

Conversions
Column 1: Desired in px | Column 2: Outcome in em
 0px =  .000 em
 1px =  .083 em
 2px =  .166 em
 3px =  .250 em
 4px =  .333 em
 5px =  .416 em
 6px =  .500 em
 7px =  .583 em
 8px =  .666 em
 9px =  .750 em
10px =  .833 em
11px =  .916 em
12px = 1.000 em
13px = 1.083 em
14px = 1.166 em
15px = 1.250 em
16px = 1.333 em
17px = 1.416 em
18px = 1.500 em
19px = 1.583 em
20px = 1.666 em
21px = 1.750 em
22px = 1.833 em
23px = 1.916 em
24px = 2.000 em

Again, the formula is: desired-font/parent-font = font-in-em (i.e. 10/12 = .833em)

Hope this helps!

Sizing Text with EMs

EMs can be tricky to deal with.  To sum them up, however, they basically allow for resizing of text in Internet Explorer.  If you set the text to a pixel value, IE doesn't allow for resizing of that text.  It seems obvious why (to preserve your intended designs) but other browsers don't have this rule.
Here are some basic rules:
  • The default font-size at 'medium' on regular browsers is 16px
  • EMs are dependant on their parent element's size
With that said, here is an example of working with EMs:
  • Default browser size: 16px
  • Intended font-size: 12px
  • Value in EMs: 12/16 = .75em
Remember when calculating EMs that the EM inherits its denominator (in the equation) from the parent font size.  The calculation is also based on pixel values.

For further reading on EMs check out the following sites:



Thursday, November 6, 2008

CSS Cheat Sheet

Another great cheat sheet to help when you can't remember syntax.  This one is for CSS!  The guys at addedbytes make these and they're really useful!  Great stuff.

Mod_rewrite cheat sheet

A great cheat sheet for mod_rewrite syntax.

MOD_REWRITE Cheat Sheet (V2)

Simple form confirmation

If you want a simple form confirmation, here you go:

<form onsubmit="return confirm('Are you sure you want to send this?');">

Just make sure the onsubmit is in your form tag and it will have a popup dialog confirming the submission of the form.  Very simple.

Friday, October 31, 2008

SQL Random Rows

Select a random row with MySQL:

SELECT column FROM table ORDER BY RAND() LIMIT 1

Select a random row with PostgreSQL:

SELECT column FROM table ORDER BY RANDOM() LIMIT 1

Select a random row with Microsoft SQL Server:

SELECT TOP 1 column FROM table ORDER BY NEWID()

Thanks to: http://www.petefreitag.com/item/466.cfm

Monday, October 27, 2008

MySQL DATETIME and PHP

If you ever had trouble with the date conversions between MySQL's DATETIME field and PHP's date function, here is a way to deal with them.

If you want to take the date from MySQL and display it a certain way with the DATE function in PHP you first need to convert it.  Use the following code:

date(formatstring, strtotime($rowentry));

formatstring is your format string for your date (see date reference)
strtotime is a function in PHP that takes a string
$rowentry is the DATETIME data from your MySQL database

Monday, October 13, 2008

SEO: mod_rewrite and dynamic pages

Search engines don't really like urls that look like http://mysite.com/page.php?id=1&type=23.  Parameters in the URL throw off some search engines and others refuse to index such pages.  To get around this, and still keep your dynamic information, you can do with the mod_rewrite approach with Apache.

This solution is only for the Apache web server.  If you're using another server, such as Windows, you'll need to figure something else out.

The following link details how to use mod_rewrite to have urls that look like http://mysite.com/pages/mypage/mysubpage function like the url at the top.  http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Thursday, October 9, 2008

SQL JOIN References

I had a previous post about LEFT JOINS but I believe w3schools does a better job at explaining them.

Wednesday, October 8, 2008

Background:none doesn't work (in IE)

Something as simple as "background: none;" when placing a "like" item within another doesn't work in IE7 OR IE6.

<ul id="mainNav" style="">

<li style="" class="group1"><a href="#" onmousedown="showhide('mainSubGroup1')">Energy &amp; Resource Management</a>

<ul id="mainSubGroup1">

<li id="s-t01"><a href="#" style="">Environmental Stewardship</a></li>

<li id="s-t02"><a href="/energy/index.php" style="">Climate Savers Computing Initiative</a></li>

<li id="s-t03"><a href="#" style="">Parking and Transportation Services</a></li>

<li id="s-t04"><a href="#" style="">Utilities and Plant Engineering</a></li>



</ul>

</li>



IF there is a background of some sort on the first <li> item, the items in the next level will use them as well. Adding "background:none;" does not work. Must replace with something.

Tuesday, October 7, 2008

Default Firefox Style Sheet

I was trying to find the default CSS used in Firefox and finally found out how to do it.

Simply paste the following into your browser window: file:///C:/Program%20Files/Mozilla%20Firefox/res/html.css


Monday, September 29, 2008

MySQL Count Distinct

I was having trouble trying to count up the number of enries in a database.  I was doing a join and wanted only the unique entries from another table so that I wouldn't get a inflated count.

You can do a COUNT with the DISTINCT tag in it to accomplish this.

Example:
SELECT COUNT(DISTINCT results) FROM student;

Thursday, September 25, 2008

Flash ASCII Code

If you need ASCII characters (+, > , %, etc) this link will give you all the values to put into the text file (txt, php, whatever) for translation to Flash textareas.



Friday, September 12, 2008

IIS7 Custom Error Pages & Debug Information

Ever wanted to create custom error pages or change the default debug information that is displayed with IIS?

Thursday, September 4, 2008

PHP Cheat Sheet

This is an interesting little cheat sheet for PHP.  It doesn't cover a whole lot of functions, but it does have some that are used often.  Might save you  a lot of time.

SEO: Stopping Search Engine Indexing

If you wanted to stop Google from indexing your website (or any other search engine) you can include a robots.txt file on your server.  This file is checked by search engine bots before indexing and they follow whatever rules you put in there.

You can find detailed information on how to write your robots.txt here: http://www.google.com/support/webmasters/bin/answer.py?answer=40360


Wednesday, September 3, 2008

Search button and field alignmnet

CSS DOCUMENT

#email {

margin: 0px 2px;
width: 110px;
_width: 110px;
padding: 2px 2px 0 2px;
_padding-right: 18px;
height: 16px;
_height: 16px;
background-color: #FFF;
border: 1px solid #afa9a6;
-moz-box-sizing: content-box;
float:left;
font-size:10px;
}

.search { background-image:url(/images/layout/speedclub_signup.gif); }

button.icon-replace {
-moz-outline: none;
padding: 0;
border-style: none;
background-color: transparent;
background-repeat: no-repeat;
background-position: center center;
margin:0;
}

.icon-replace {
background-repeat: no-repeat;
background-position: center center;
display: inline;
display: inline-block;
display: -moz-inline-box;
_display: inline;
zoom: 100%;
width: 44px;
padding: 0 !important;
overflow: hidden;
white-space: nowrap;
text-align: left;
word-spacing: -2ex;
letter-spacing: -2ex;
min-height: 20px;
_height: 20px;
color: transparent !important;
_font: 1px/0 monospace;
_word-spacing: -2px;
_letter-spacing: -2px;
}



WITHIN HTML
<input name="email" id="email" class="speedclub_input" type="text">

<button type="submit" id="search-submit" class="icon-replace search"><span style="display: none;">Search</span></button>

MSSQL Count Query

The count query is very useful in SQL.  Below is the syntax:

SELECT COUNT(thefield) AS outputvariable FROM tablename GROUP BY thefield HAVING anyfield = yourvalue

  • thefield is what you want to count
  • outputvariable is what you want the count to be saved in
  • tablename is the name of the table to look into
  • anyfield is any field you want to use as a criteria
  • yourvalue is the value for your criteria

This may also work the same for MYSQL.

Friday, August 29, 2008

MSSQL Data Types

Sometimes it gets confusing trying to figure out what all the SQL Server data types really are for. It seems, to a novice, that they have too many... but in reality they all serve a purpose.

Below is a table that gives a brief description of each of these data types.


Data Types Description
bigint Integer data from -2^63 through 2^63-1
int Integer data from -2^31 through 2^31 - 1
smallint Integer data from -2^15 through 2^15 - 1
tinyint Integer data from 0 through 255
bit Integer data with either a 1 or 0 value
decimal Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1
numeric Fixed precision and scale numeric data from -10^38 +1 through 10^38 -1
money Monetary data values from -2^63 through 2^63 - 1
smallmoney Monetary data values from -214,748.3648 through +214,748.3647
float Floating precision number data from -1.79E + 308 through 1.79E + 308
real Floating precision number data from -3.40E + 38 through 3.40E + 38
datetime Date and time data from January 1, 1753, through December 31, 9999,
with an accuracy of 3.33 milliseconds
smalldatetime Date and time data from January 1, 1900, through June 6, 2079,
with an accuracy of one minute
char Fixed-length character data with a maximum length of 8,000 characters
varchar Variable-length data with a maximum of 8,000 characters
text Variable-length data with a maximum length of 2^31 - 1 characters
nchar Fixed-length Unicode data with a maximum length of 4,000 characters
nvarchar Variable-length Unicode data with a maximum length of 4,000 characters
ntext Variable-length Unicode data with a maximum length of 2^30 - 1 characters
binary Fixed-length binary data with a maximum length of 8,000 bytes
varbinary Variable-length binary data with a maximum length of 8,000 bytes
image Variable-length binary data with a maximum length of 2^31 - 1 bytes
cursor A reference to a cursor
sql_variant A data type that stores values of various data types,
except text, ntext, timestamp, and sql_variant
table A special data type used to store a result set for later processing
timestamp A database-wide unique number that gets updated every time
a row gets updated
uniqueidentifier A globally unique identifier


The table was taken from: http://www.databasejournal.com/features/mssql/article.php/2212141

ASP Directory Listing

Ever wanted to list the contents of a directory? I found this very useful when developing a site for one of our clients. You can use it to allow them to select files to use or really anything...

Here was my reference for this: http://www.brainjar.com/asp/dirlist/

I modified what they had to exclude files so that the user would only get the files I wanted them to see. Putting this information in a dropdown list can be very useful, but you could also list it out if you wanted.

ASP RecordSet Reference

When dealing with SQL queries its important that you understand RecordSets in ASP. It's pretty straight forward but since there are a lot of methods association with this object, its good to have a reference.

Here's a reference for you all: http://www.itechies.net/tutorials/asp/index.phpindex-pid-rec.htm

Date & Time Formats in ASP and MSSQL

ASP is terrible when it comes to formatting of dates. When putting your date into MSSQL (SQL Server), you probably will encounter issues with the date not being when you entered. A major note is to make sure you include single quotes around your date when making your SQL query. If you don't, you probably won't get the date you intended.

Here is a reference for formats supported in MSSQL for the datetime field. The article also gives an explanation of the difference between DATETIME and SMALLDATETIME.

http://www.databasejournal.com/features/mssql/article.php/2191631

Displaying Large Text with PHP/ASP from SQL

This is an issue I faced with both PHP and ASP. When I set a field type in SQL to varchar(max) or some large amount, when I attempt to display this information via the server-side language, nothing displays.

I found online an explanation for ASP:

After some testing I found there are no SQL Server 2005 data types
that can be read by an ASP page that hold more than 8000 characters. I
speculate that the 2-byte field length indicator is not read by ASP.
Maybe the field length of the old Access memo data type was encoded
differently. - kirkatsfw-ga
I also found something similar related to PHP. My solution in both cases was as stated above, to reduce the limit for the field to something that the server-side languages could deal with. This was the case with both PHP and ASP along with both MySQL and MSSQL.

Thursday, August 28, 2008

ASP Functions List

I found a nice list of functions in ASP.

Here it is: http://www.haneng.com/FunctionSearch.asp?s=a

Wednesday, August 27, 2008

ASP & MSSQL Query Examples

Here are some code examples for doing things in ASP with MSSQL (SQL Express):


Setup the Connection
'Setup the connection
Dim aConnectionString

aConnectionString = "Driver={SQL Native Client};Server=sitename\sqlexpress;Database=databasename;Uid=username;Pwd=password;"

'Connect to DB
Dim conn, R, SQL, RecsAffected

Set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = adModeReadWrite
conn.ConnectionString = aConnectionString
conn.Open

Setup RecordSet & List all Entries


'select a record set
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * from table", conn

do until rs.EOF
for each x in rs.Fields
response.write(x.name)
response.write(" = ")
response.write(x.value)
next
rs.MoveNext
loop

rs.close


Select an Entry & See if it Exists

set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Select * FROM tablename WHERE fieldname = 'fieldvalue'", conn

'check if login worked
dim found

if rs.BOF and rs.EOF then
'no entry found
found = false
else
'entry found
found = true
end if


Add an Entry


'add an entry
'conn.Execute "INSERT INTO tablename (fieldnames) VALUES (fieldvalues)"

Delete an Entry

'delete an entry
'conn.Execute "DELETE FROM tablename WHERE fieldname = 'fieldvalue'"

Update an entry

'update an entry
'conn.Execute "UPDATE tablename SET fieldname = 'somevalue' WHERE fieldname = 'fieldvalue'"

There's a lot more but these are some for reference purposes.

Resource for Connection Strings

Every get stuck trying to figure out how to connect to a database? I had this trouble when trying to get into a MS SQLExpress database. It just wouldn't connect... but I knew it was my problem.

Here is a great site for connection strings: http://www.connectionstrings.com/

Friday, August 22, 2008

Removing Line Breaks with Dreamweaver

Well my last post took me forever to post. It seems blogger is dumb even in HTML code and takes line breaks literally... ? Meaning every line break was treated like one, even in HTML mode, which doesn't make any sense.

So I searched online and found out how to remove them with Dreamweaver. Its pretty cool. This is the process:
  1. Open a document,
  2. Click inside Code View,
  3. Create an empty line,
  4. Left-click in the margin on the left hand-side of that empty line (it should turn black on Windows, blue on Mac),
  5. Select Menu > Edit > Find and Replace (keyboard shortcut: Ctrl + F),
  6. Select an option in the "Find in:" dropdown box,
  7. Select "Replace All" and you're done.

The source of this was here: http://www.tjkdesign.com/articles/whitespace.asp

Really really helpful! I'm sure I'll use it again.

Javascript Event Handlers

I wanted a quick list of event handlers so here they are. This is courtesy of our friends at the w3schools.

FF: Firefox, N: Netscape, IE: Internet Explorer

AttributeThe event occurs when...FFNIE
onabortLoading of an image is interrupted134
onblurAn element loses focus123
onchangeThe user changes the content of a field123
onclickMouse clicks an object123
ondblclickMouse double-clicks an object144
onerrorAn error occurs when loading a document or an image134
onfocusAn element gets focus123
onkeydownA keyboard key is pressed143
onkeypressA keyboard key is pressed or held down143
onkeyupA keyboard key is released143
onloadA page or an image is finished loading123
onmousedownA mouse button is pressed144
onmousemoveThe mouse is moved163
onmouseoutThe mouse is moved off an element144
onmouseoverThe mouse is moved over an element123
onmouseupA mouse button is released144
onresetThe reset button is clicked134
onresizeA window or frame is resized144
onselectText is selected123
onsubmitThe submit button is clicked123
onunloadThe user exits the page123

Listing can be found here: http://www.w3schools.com/jsref/jsref_events.asp

CSS Lists

Formatting list items is always tricky with css. There are so many combinations of what you can do and then there's browser differences with padding and margins.

This is a good reference if you'd like to Tame CSS Lists: http://www.alistapart.com/articles/taminglists/

Today you can do a lot with lists because you can make them look like whatever you want. So they are an ideal choice for navigation menus, lists of information, or whatever creative ideas you might have.

Thursday, August 21, 2008

MYSQL Left Join & More

This may seem simple to others but I found a good reference for MYSQL query syntax. Sometimes queries can get crazy and confusing, so its good to read up and make sure you're doing everything right.

http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php

Wednesday, August 20, 2008

Cookies with ASP

I found some references for cookies with ASP that I wanted to save. These sites were good at helping me with the syntax because it is slightly different than what I'm used to in PHP.

http://www.w3schools.com/asp/asp_cookies.asp

http://riki-lb1.vet.ohio-state.edu/mqlin/computec/tutorials/aspcookie.htm

Thursday, August 14, 2008

Download File Script for ASP

Well after tons of frustration with ASP (which sucks in my opinion), I was finally able to find a way to download files properly. So, if you every wanted to make it so your links aren't straight to the files, but to an intermediate page first, here you go. In PHP this is much simpler, FYI...

<%
Response.Buffer = True
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'Set this to the variable in your GET
Set filename = request.QueryString("wp")
'-- set absolute file location
strAbsFile = Server.MapPath(filename)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("Le fichier est inexistant.")
End If
Set objFSO = Nothing
%>


P.S. I hacked this out from some download manager but don't remember it to give proper credit (sorry).

Pause Flash

// sec = number of seconds

function paused(sec) {
stop();
var i = sec - 1;
var t = setInterval(function () {
if (i == 0) {
clearInterval(t);
play();
}
i--;
}, 1000);
}

Then in a frame add:
paused (sec); // change sec to the number of seconds for the pause


Wednesday, August 13, 2008

PHP to ASP Quick Reference

I'm a PHP developer but the demands of clients always make you learn things you really don't want to... so I had to learn ASP (VBScript). I think the hardest part about learning a new language is the syntax, but I guess that's the only real difference, right?

Anyway, ASP is much different than PHP, in more ways than one. I won't get into them but if you're struggling to learn it, or if you know ASP but are struggling with PHP this is a very useful reference: http://www.design215.com/toolbox/asp.php

It saved me a lot of time because if you've tried to search for ASP code, like I have, you'll know it is much harder than looking for PHP references.

Quick AJAX Reference

I started working with AJAX this past summer and had one reference that really helped me the most. The site is: http://www.captain.at/howto-ajax-form-post-request.php

AJAX seems intimidating because it's new and cool but it really isn't. Simply put, it is a combination of JavaScript and a server-side language such as PHP. It's just about sending and receiving data through JavaScript to a server-side encoded page (PHP page) and displaying the output information to a user without refreshing their browser.

I'm finding that each new site that I do, I end up adding a little bit of AJAX flavor, so I'm sure we'll be finding more tips and tricks with it.

Blog Begins

Well, we've been talking about making a blog of useful stuff so here we go. This is just miscellaneous cool things we've found online (or from ourselves) related to web development/design.

If you find anything useful, link to it and let others know. Thanks!