Community Blogs

Uploading files with PHP

During my recent project I learned about uploading files using. For uploading files with PHP first step is to create a HTML form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  <HTML>  

<BODY>    <FORM METHOD='POST' ACTION='upload.php' ENCTYPE='multipart/form-data'> 

<INPUT NAME="image" TYPE="file" />           <INPUT TYPE='Submit' VALUE='Upload' />  






For form the attribute ENCTYPE='multipart/form-data' is very important.

Next step is to create a PHP script upload.php which will upload the file:


// Path where the file will be uploaded  
$target_path = "/var/www/";  
$file  = $_FILES['image'];  
$temp = $file['tmp_name'];  
   if(move_uploaded_file($temp, $target_path.$file['name']))  
      echo "Upload successfull.";  
      echo "File type is: ".$file['type'];  
      echo "File size is: ".$file['size']/1024. " kb";  
      echo "File cannot be moved to $target_path";  
  echo "Unable to upload!";  

The target path given is an absolute path. I tried to give relative path but it didnt work. If you are using windows you can give path like "c:\\some_directory\\".


Linux Screenshots


Here is a whole page of screen shots of Linux Distributions

by cybormoron:
  • Screenshot/slideshow of Slackware 12.2 install
  • Here are some screenshots of Vector Linux 5.9 Gold Edition
  • How to create a virtual machine with Virtual Box
  • Slackware and D Small Linux in Virtual Box
  • Freespire in Virtual Box
  • PCLinuxOS in Virtual Box
  • Wolvix in Virtual Box
  • Debian in Virtual Box 

On email account recovery (how to make it not stupid)

This great article by John Timmer and a discussion with Aaron Toponce on Identica provoked this blog entry.

There's been some talk about "security" questions and how they are used to allow access to your email account when you forget your password. Generally you have a few obvious options that anyone could dig up with a few minutes on the Internet. Gmail takes it a step further and lets you create your own question. I can confidently say these measures are worthless to the average user.

Instead, I'll tell you how I sidestep the problem and keep your email account accessible to you and safe from snoopers who looked up what street you grew up on.

Pick a random file, preferably a big one that you have the only exact copy of. Run it through sha1sum (or any reasonable hash function). See where I'm going? Save that hash in a text file somewhere safe, on multiple computers or media is possible. That hash is your first/favorite pet's name. Or your mother's maiden name. Or your favorite color when you were 7.

You see what you did there? The answer to the security question is virtually unguessable now. I don't care how savvy the social engineers are or how strong their Google-fu might be. No one is going to find that hash in Wikipedia. You have changed the security question from a second password (a "something you know" factor) to a token you have to posess (a "something you have" factor). Multi-factor authentication FOR THE WIN.

But let's go a step further. Someone could gain access to wherever you stored the text file that holds the hash. You can't email the file to yourself, because (1) you have to trust your email host to prevent unauthorized access to your email and (2) you need access to your email to get access to your email (Catch-22). You need to encrypt the file.

I use Gnu Privacy Guard for this step. Since I already have a key, I can just encrypt the file to myself. At this point I can store copies everywhere, even where others might have access!

If you're using Gmail and want a reminder where you have your hash token, pick this for your question: "What's in emailemergency.txt.gpg?" If you're sneaky, put something like "Am I right-handed?"

Congrats. You have just taken a stupid insecure system and made it useful. I hope you like it.

Avoid common querying mistakes with better Django models

This article sheds light on some of the lesser-known features of the Django ORM in particular, but SQLAlchemy users may find some of the cautions about inefficient query generation applicable to their own code. Learn how to avoid common querying mistakes, use model managers to encapsulate complex queries, and take advantage of the powerful new aggregation features available in Django V1.1

Linux after work

After a day of working with Nagios on Linux, I went home an reinstalled my laptop. I installed Linux of course. I installed Ubuntu 9.04 in stead of Debian.

Nagios is one of my favorite applications for Linux. The monitoring options are incredible. I want more people to monitor there environment with nagios.


NOOB's adventures in Linux From Scratch

 Hello again,

   Today has been a wonderful day. I was looking for a kinda recipe for the command line. No one was able to help me. I would ask around chats and they'd say read the man pages. All fine and good if you know what you're looking at but man pages have always been very cryptic for me. Info pages seem a bit better but I need nuts and bolts and I guess I really couldn't get to the core of what I needed. Then a gentleman who overheard me on IRC complain about a user's guide.. pointed me to ... At first I was a bit conserned I'd been had as this page was extracting :O But what soon followed was pure pleasure.

   Here , I'd found what I was looking for, ( I think ) I could read it. I didn't need a scientific dictionary , I didn't feel like a total fool . It's wonderfully written. The Author goes on to state that he would like you to have a Redhat "like" or debian "like" distribution installed so if he ask you can have available the program to use.

   then he put me right at ease by saying:

Any system reference will require you to read it at least three times before you get a reasonable picture of what to do. If you need to read it more than three times, then there is probably some other information that you really should be reading first. If you are reading a document only once, then you are being too impatient with yourself.

Next , I get a really big smile when I read :

The LPI and RHCE are two certifications that introduce you to LINUX. This book covers far more than both these two certifications in most places, but occasionally leaves out minor items as an exercise. It certainly covers in excess of what you need to know to pass both these certifications.

  Wow, not only do I feel like I'm learning alot and even understanding man pages now that before I started this book didn't have a clue , man pages overwhelmed me. I even am beginning to feel comfortable with the command line.

   I might even qualify for some certifications that weren't my primary objective.

   Right now I'm reading mostly man pages as an exercise , mostly from coreutils and reviewing many of the primary commands.

Think it's been 12 days or so since I decided to try and build LFS... right now it's not looking like it's going to be as long a journey as I once thought. 




Guess what, I have SPLAT in my notebook, easy to install and easy to use. :)


Dual Boot Mac Mini

I was pleasantly surprised that changing a Mac Mini to dual boot Mac OS X and Linux was relatively painless. I more or less followed the instructions here:

I ran the Boot Camp thing in the Utilities folder and allocated the disk half and half.  (I was kind of annoyed that it assumed I was going to install Windows.)

Then I installed the rEFIt boot manager:

Finally, I installed Ubuntu 9.04.  The only problem now is that the display comes up in 800 x 600 when I boot into Linux.



Just„ÄÄstarted Local Drupal Group


I happen to be a Drupal user. But in Japan Drupal is not popular.

日本では商用ではMoovable Type,オープンソースではXoopsが人気のようですね。

In Japan, Moovable type and Xoops is popular.


And I was looking for a users on the net and found and decide d to have meet up events.


At the first meeting we have 18 users.


This weekend is 2nd time gethering, and 8hours.




NEWB's adventures in Linux From Scratch

  Hello again,

   It seems I have the talent for sticking my foot in my mouth. I've just recently been informed that noob stands for : someone who believes they know it all , but in reality know little to nothing at all.  I stand corrected. (I though I said I was a newbie)

   Now that I've apparently found a book that I can understand,  learning is becoming much easier. I'm starting to organize.  Many of the things will save me time like the bash ctrl key functions so I've made a kind of overlay (remember Word Perfect?) that way I'll learn much faster. Seems that there are list and notes everywhere  in this book. There's a lot to learn and I've got to have somewhere easy to recall the most important things. For me that's a real paper notebook. 


FFMPEG Cropping and Re-sizing (order matters)

I discovered something whilst trying to crop and re-size a video with FFMPEG: the order of switches actually matters! I couldn't find any mention of this in the documentation, and nowhere could I find an explanation of why my video was being cropped after it was resized. The video I was re-encoding had some fuzziness at the top, and an ugly black border down the right-hand side. I wanted to remove these, but have a fixed output size.

Here's an example. Our input file, input.avi is a 640x480 video.

We run the following 2 commands:

ffmpeg -i input.avi -s qvga -croptop 8 -cropright 22 output1.avi
ffmpeg -i input.avi -croptop 8 -cropright 22 -s qvga output2.avi

Notice that in the first case, we've set the size first (qvga means 320x240).

In the second case we set the cropping first.

Now let's look at the output with: file *.avi.

input.avi: RIFF (little-endian) data, AVI, 640 x 480, 25.00 fps, video: XviD, audio: MPEG-1 Layer 3 (stereo, 44100 Hz)
output1.avi: RIFF (little-endian) data, AVI, 298 x 232, 25.00 fps, video: FFMpeg MPEG-4, audio: MPEG-1 Layer 1 or 2 (stereo, 44100 Hz)
output2.avi: RIFF (little-endian) data, AVI, 320 x 240, 25.00 fps, video: FFMpeg MPEG-4, audio: MPEG-1 Layer 1 or 2 (stereo, 44100 Hz)

As you can see, the first output file has its dimensions cropped after resizing. The second one before, and its the second one I wanted, cropping the video first, then resizing it.

I have never encountered a command-line app where the order of the switches actually mattered, until now. I don't know how many other ffmpeg switches this also applies to, but I thought I'd share it as I personally couldn't find anything about it elsewhere.

Hope this is helpful!


Page 116 of 139

Upcoming Linux Foundation Courses

  1. LFD312 Developing Applications For Linux
    16 Feb » 20 Feb - Atlanta - GA
  2. LFD331 Developing Linux Device Drivers
    16 Feb » 20 Feb - San Jose - CA
  3. LFS220 Linux System Administration
    16 Feb » 19 Feb - Virtual

View All Upcoming Courses

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board