Archive

Posts Tagged ‘PHP’

[PHP] Shortcuts of If-Else statement

April 5th, 2009

When I learn PHP last September 2005, I was little bit confuse in PHP if-else statement… especially a statement contains with ? and : but somehow, I got it right. I post this cause somebody ask again what’s the difference. So told him, its all the same and its just a shortcuts.

<?php

$authenticated = true;

// [1] standard if-else statement
if ($authenticated)
{
     echo
‘YES’;
}
else
{
      echo ‘NO’;
}

// same with [1] :P
if ($authenticated) { echo ‘YES’; } else { echo ‘NO’; }

// [2] lil bit shortcut
if ($authenticated)
      echo ‘YES’;
else
      echo ‘NO’;

// [3] the shortcut
echo $result = ($authenticated) ? ‘YES’ : ‘NO’;

?>

Or let me say its an evolution of if-else statement… Hahaha.. or maybe the laziness of the programmer. :P So got it? hehehehe..

Camilo III Info.Tech, PHP, Web Development , ,

[PHP] How to upload a file

April 2nd, 2009
Comments Off

I would like to share this script to all since most of my friends ask how to create an upload script using PHP.

Download the PHP script at;

  1. Main Download: Simple Upload Demo (5)
  2. Mirror 1: simple_upload.zip

Upload File Demo: http://www.cable21.net/camilord/simple_upload/index.html

Modification according to your preferred setup

Its default upload directory is uploads/ and to change this, just change the line 19;

// set upload destination
$uploaddir = “uploads/”;

In the script, it is capable to validate allowed file types. As default, images files are only allowed to be uploaded. To change this, just edit the upload.php at line 37.

// allowed file types
$validMIME = array(‘jpg’,‘jpeg’,‘bmp’,‘png’,‘gif’);

Just add any file extension you want to allow… Sample;

// allowed file types
$validMIME = array(‘jpg’,‘jpeg’,‘bmp’,‘png’,‘gif’,‘doc’,‘zip’,‘pdf’);

So I just allowed Document, Zip and PDF files…

That’s all.. I think everything is understandable.. hehehe.. Please read also the comments.

Camilo III Info.Tech, PHP, Web Development , , , , , ,

PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4800 bytes)

February 9th, 2009

When I first encountered this error, I thought something wrong with my apache-php integration. Thank God it’s not the one I thought.

This PHP Fatal error message will be encountered if your PHP script memory requirements exceed the default 8MB limit. Somehow, you can overcome this by doing two methods.

1. Set Resource Limits in /etc/php.ini

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 45 ; Maximum execution time of each script
max_input_time = 60 ; Maximum amount may spend parsing request data
memory_limit = 12M ; Maximum amount of memory a script may consume (8MB)

2. Initiate a function to set the Resources Limit

ini_set("memory_limit","12M");

Why so serious?!? that’s it… your done! :)

Camilo III Administration, Info.Tech, Web Development , , , , , , ,