Uroci.net - !
Adobe Photoshop Adobe Illustrator Adobe Flash Adobe Fireworks DreamWeaver CSS HTML Corel Draw Image Ready PHP
PHP
SEO CMS Microsoft Windows Microsoft Word Microsoft Excel PowerPoint Microsoft Access Microsoft Publisher Linux Visual basic JavaScript Ajax 3ds Max Maya 3D C++ Sound Forge Gimp SWiSH

File Upload

PHP » PHP
nma   :    : 4320



Section #1
, , .

$file_name = .
$extension = , . strrchr() character .
$ext_array = .
$ext_count = .

<?php
//SECTION #2
if (!$file_name) {
return false;
} else {
if (!$ext_array) {
return true;
} else {
foreach ($ext_array as $value) {
$first_char = substr($value,0,1);
if ($first_char <> ".") {
$extensions[] = ".".strtolower($value);
} else {
$extensions[] = strtolower($value);
}
}
?>


Section #2
. $file_name , , false, , . $ext_array . , , . foreach() . , , , $extensions.

<?php
//SECTION #3
foreach ($extensions as $value) {
if ($value == $extension) {
$valid_extension = "TRUE";
}}
?>


Section #3
. $extensions , . if , . if , , $valid_extension true. , .

<?php
//SECTION #4
if ($valid_extension) {
return true;
} else {
return false;
}}}}
?>


Section #4
, $valid_extension . , true , false. (3) , (2) if-elseif .
---------------------------

Function #2 (Validation of File Size)


<?php
function validate_size() {
$temp_file_name = trim($this->temp_file_name);
$max_file_size = trim($this->max_file_size);

if (!$temp_file_name) {
$size = filesize($temp_file_name);
if ($size > $max_file_size) {
return false;
} else {
return true;
}
} else {
return false;
}
}
?>


- . (2) $temp_file_name $max_file_size, . . $temp_file_name , , false. $temp_file_name , - $max_file_size. - "false", "true" .
--------------------------

Function #3 ( ?)

<?php
function existing_file() {
$file_name = trim($this->file_name);
$upload_dir = $this->get_upload_directory();

if ($upload_dir == "ERROR") {
return true;
} else {
$file = $upload_dir . $file_name;
if (file_exists($file)) {
return true;
} else {
return false;
}
}
}
?>


, upload, . . , , , upload . , upload- , , . id database , id . (.. hello_world.php 452.php, 452- DB) , . , class, .

(2) , $file_name $upload_dir. if-elseif . if : upload. , exit true. , true, , . 'exisiting_file()', true, file exists . upload directory , if-elseif .

the file name intact(,), .. $file = $upload_dir . $file_name. , PHP file_exists(). file exists, true, false .

-------------------------------
Function #4 ( )


<?php
function get_file_size() {
//SECTION #1
$temp_file_name = trim($this->temp_file_name);
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;

//SECTION #2
if ($temp_file_name) {
$size = filesize($temp_file_name);
if ($size < $kb) {
$file_size = "$size Bytes";
}
elseif ($size < $mb) {
$final = round($size/$kb,2);
$file_size = "$final KB";
}
elseif ($size < $gb) {
$final = round($size/$mb,2);
$file_size = "$final MB";
}
elseif($size < $tb) {
$final = round($size/$gb,2);
$file_size = "$final GB";
} else {
$final = round($size/$tb,2);
$file_size = "$final TB";
}
} else {
$file_size = "ERROR: NO FILE PASSED TO get_file_size()";
}
return $file_size;
}
?>

, . (2) - .

<?php
//SECTION #1
$temp_file_name = trim($this->temp_file_name);
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;
?>



: «1 2 3 4 5 »

(1)

yahoo 24.02 2007 14:28.
upload- ' . $_FILES['upload']['name'] str_replace ?

,


© . 2006-2008. Created by: Site.bg
: IT | | . | Paparak.bg | | uchenik.com | TRAVEL | | AmAm.bg | . | | AnimeS-bg.com | | | | IT Light | Spodeli.net | - | IDG.BG | Teenproblem.net | - | Fresh-BG.com | Hanovete.com | Bulfleet.com | Mythlands.com | Ohoboho.com | .Com | News24 | Setcom.bg | Atol.bg | Elmaz.com | MobileBulgaria.com