Playing with PHP and my newly set up server!

I am ill for two days...only fever though! I am on holiday and my university will not open until 12th of November.

By the way, I have got a comment on the last post. It's great feeling. For it is the first time I got any comment on any post. Of course, I never blogged as seriously as this!

In my long holidays I try to learn new things by myself. This time I am working with php and web server.

After setting up the web server I tried if I can access the computer from outside, I mean from another computer over the internet. I learned that the port on which the web server is running is to be forwarded. I did so in the router (GLB-502T) and 'lo and behold' the homepage is displayed when I typed the ip-address followed by the port number. My ISP does not give static ip-address, so the ip-address changes each time I connect to the internet. The page also opens on my mobile web browser through gprs.

Yesterday, I was trying to upload files to server(my computer!) using PHP. I found this script on the internet.




<html> <?php

// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.

if(!empty($_FILES["userfile"])) {

$uploaddir = "uploads/"; // set this to wherever

//copy the file to some permanent location

if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir . $_FILES["userfile"]["name"])) {


echo("file uploaded");

}

else {

echo ("error!");

}

}

?>

</html>

It is to be saved as "uploader.php". You also need to have a html form to select the file to upload. Here is the code for "upload.htm"




<html>
<form action="uploader.php" method=post enctype="multipart/form-data">
submit this file: <input type=file name="userfile"><br>
<input type=submit><br>
</form>
</html>

A new folder 'uploads' is to be created in the same location where uploader.php is.

It worked well. This also solved another problem. My brother has a mobile phone from which data transfer with the computer is a problem as it doesn't support bluetooth, and he doesn't have a supported data cable. Now, a file can be uploaded from the mobile directly to my computer (through the mobile web browser). And it is so quick!

You should not use the above php script on public websites. It is full of security vulnerabilities. Anyone can upload a virus or take control of your system.

Update: Click here to find out how to run a server on dynamically assigned IP

Comments

Popular posts from this blog

Power On Your Computer by Keyboard, Mouse or Alarm

Comet Lulin Comes Closer

Into the World of Computer Gaming