Escape characters in PHP

By San March 23rd, 2012, under Software, Web

I was writing a simple php page to list the files in the directory and generate hyperlink to download them. It should be a very easy job, but something went wrong, as always. The escape characters cause the hyperlink to be cut in half and the link was broken. So to fix that, those characters should be replaced before been send to the httpd. So here it is:


$m_fr = str_replace("%","%25","$m_fr"); // % -> First!!!

$m_fr = str_replace(" ","%20","$m_fr");
$m_fr = str_replace("#","%23","$m_fr");
$m_fr = str_replace("&","%26","$m_fr");
$m_fr = str_replace("+","%2B","$m_fr");
$m_fr = str_replace("/","%2F","$m_fr");
$m_fr = str_replace("=","%3D","$m_fr");
$m_fr = str_replace("?","%3F","$m_fr");

And the whole page:


<!-------------------------------------
 |    List Dir Funtion w. Upload       |
 |          Version: 1.0.04            |
 |              By: San                |
 |         s(at)zhujunsan.net          |
  -------------------------------------->

<html><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>List</title>
<body>
<?php
if ($_FILES)
{
	if ($_FILES["file"]["error"] > 0)
	  {
	  	echo "Error: ".$_FILES["file"]["error"]."<br />";
	  }
	else
	  {
		  echo "Upload: ".$_FILES["file"]["name"]."<br />";
		  echo "Type: ".$_FILES["file"]["type"] . "<br />";
		  echo "Size: ".(round($_FILES["file"]["size"]/1024, 2)).
		  	"kb(". ($_FILES["file"]["size"] ) .")<br />";

	    if (file_exists("upload/" . $_FILES["file"]["name"]))
	      {
	      echo $_FILES["file"]["name"] . " already exists. ";
	      }
	    else
	      {
	      move_uploaded_file($_FILES["file"]["tmp_name"],
	      "./".$_FILES["file"]["name"]);
	      echo "Files stored: ".$_FILES["file"]["name"]."<p>";
	      }
	  }
}

if($_GET["upload"]=="Password"||0) //Change Password to whatever you like. Be aware this is still unsafe, just preliminary protect.
	{
		echo "<form action=\"list.html\" method=\"post\"
		enctype=\"multipart/form-data\">
		<label for=\"file\">Filename:</label>
		<input type=\"file\" name=\"file\" id=\"file\" /><br />
		<input type=\"submit\" name=\"submit\" value=\"Submit\" />
		</form>";
	}

 function tree($folder) {
    $mydir = dir($folder);
    while($file = $mydir->read()) {
      if((is_dir("$folder/$file")) && ($file!==".") && ($file!==".."))
      {
//        tree("$folder/$file");
      }else {
        if(($file!==".")&&($file!=="..")&&($file!=="index.html")&&($file!=="favicon.ico")&&($file!=="robots.txt")) {
        $m_f=str_replace("./","","$folder/$file"); 

        $m_fr = $m_f;

        $m_fr = str_replace("%","%25","$m_fr"); // % -> First!!!

        $m_fr = str_replace(" ","%20","$m_fr");
        $m_fr = str_replace("#","%23","$m_fr");
        $m_fr = str_replace("&","%26","$m_fr");
        $m_fr = str_replace("+","%2B","$m_fr");
        $m_fr = str_replace("/","%2F","$m_fr");
        $m_fr = str_replace("=","%3D","$m_fr");
        $m_fr = str_replace("?","%3F","$m_fr");

        echo  "<a href=$m_fr>$m_f</a><br />\r\n";
        }
      }
    }
    $mydir->close();
 }
 ?>
 <?php tree(".");?>

</body>
</html>

DIY shutter release

By San March 15th, 2012, under Arduino, Hardware, Project

This is a idea/plan that I want to do.

Lately I brought a Canon 60D, and it’s cable shutter release is using 2.5mm audio jack which is a quite common and cheap so I decide to make one or more cable shutter release/s.

From the tip to the cable, there’s three contact point. Normally there are Left | Right | GND, as using on the 60D, they defined as Shutter | Focus | GND.

Things to do:

1. Build a manual shutter release;

2. Using Arduino as a controller so time-lapse photography will be much easier.Done

So far for now, I’ll update when I make something new.

Warcraft III Resolution Changer

By San January 11th, 2012, under Program

This is a simple little program that make the Blizzard Warcraft III to fit your current screen resolution. Will you can do this by using the regedit yourself to modify the key: “HKEY_CURRENT_USER\Software\Blizzard Entertainment\Warcraft III\Video\” but this tool is much easier.

The program is in Chinese and I don’t want to change it but you can still pretty easy to use it since you only need to push one button(with the [确定更改] sign) once. If you really wanna use other language, please download the source code here: https://github.com/zhujunsan/Warcraft-III-Resolution-Changer

The program itself is at HERE.

DIY External Power Pack

By San December 12th, 2011, under Hardware, Others, Project

That’s the thing I made. I’ll edit this post with more detailed information later.

DIY External Power Pack_cost accounting

MeterialCountin CNYin USD(6.4:1)Comment
Box10.000.00from a box of Hershey's
Wire100.150.02
Glue stick30.900.14
Battery120.003.133.7v/3700mhA
protective circuit for battery13.800.59
Solar pannel16.801.064.5v/78mA
Schottky diode10.500.08ID 5819
booster circuit18.001.25pre-made, output 5V/500mA
LED10.100.02
Resister10.020.002.2k
USB mini port10.280.04
self-lock button10.330.057*7mm
capaciter30.060.011up
Battery Charger IC19.001.41MAX1555
bread board14.000.63
Total price53.948.43

QR code Message Exchanger

By San December 4th, 2011, under Arduino, Hardware, Project

This is a idea/plan that I want to do.

I wanna create a arduino project to generate QR code by itself, and using a 128×64 LCD display to show that. It can transfer short message from computer or from any senser hooked up to arduino or anything you want.

Quadcopter

By San November 7th, 2011, under Arduino, Hardware, Project

(if you don’t know what it is, google it. google image may gives you a pretty vivid impression.)

This is a idea/plan that I want to do.

I want to build a quadcopter only using arduino as the controller.

Tiny USB input device

By San November 7th, 2011, under Hardware, Project

This is a idea/plan that I want to do.

Idea comes from the computer I’m using. My old computer (HP TX1106au) has a physical mute button and you just push it and it worked. But my new computer (ASUS U36sd), will, if I want mute, I need to put Fn key and F9 which means mute, but it only works when all the system is boot up because it depends on the software to function which I don’t like.

As I know, as a HID input device, mute has a designated key value Dec 127/Hex 7F (you can find it at: http://www.usb.org/developers/devclass_docs/Hut1_11.pdf on page 56). And this blog (http://hunt.net.nz/users/darran/) give me the idea to build a usb input device though I may not use arduino in the final model. What I may use is V-USB (http://www.obdev.at/products/vusb/index.html), and the chip maybe ATMEL attiny85, the ideal size is about a Logitech Unifying Receiver.

Test ifttt

By San August 2nd, 2011, under Web

Have a little test with ifttt which I finally got an account. If it is correct, this post should been automatically linked by Facebook. Let’s see!

Got Google Apps

By San March 13th, 2011, under Web

Google is a really good and useful company! I registered Google Apps just for fun. And now I have the email address ended with @zhujunsan.net without setting up a mail server.

But one thing disturbed me is the GFW… It start dropping packages when someone access the Gmail server. Not to mention that all the IP addresses of ghs.google.com are unavailable in the China main land. So sad…

So how can I access mail.zhujunsan.net with out using ghs.google.com?

Do the nginx rewrite.

Here’s the conf file:


server {
    listen 80;
    server_name mail.yourdomain;
    rewrite ^(.*) https://mail.google.com/a/yourdomain permanent;
}

Include it into the nginx main conf file and reload the nginx. And it should work.

Google Docs and other services are very the same. Hope it’s helpful.

How to ROOT your HTC Desire Z/G2

By San February 9th, 2011, under Phone, Software

WARNING!!! THIS COULD PERMENANTLY BRICK YOUR PHONE!!! Please fully understand that this may cause some unwanted problem. Make sure you can take the risk. YOU’VE BEEN WARNED.

(This method may only works on Kernel Version: 2.6.32.21-gd2764ed. This information can be found in Settings->About phone->Software information)

First of all, let’s prepare the tools:
1. Terminal Emulator
2. VISIONary +_r14 (or Download it Here)
3. gfree(under GPL v3)
Install 1 and 2, then copy the gfree file to your tf card root.

Step 1:
Open VISIONary, set the checkbox like this:

and then click ‘Temproot now’, and wait.

Read the rest of this entry »