<?php
class commonCtrl {
var $getUploadFileName = array();
function commonCtrl(){
}
private function getRandomString($nLengthRequired = 8){
$rdm_str = md5(uniqid(rand(), true));
$rdm_str = substr($rdm_str,0,$nLengthRequired);
return $rdm_str.date("ymdHis");
}
private function is_image($file){
if (!(file_exists($file) && ($fp=fopen($file, "rb")))) return NULL;
$data = fread($fp, 8);
fclose($fp);
if (strncmp("\x00\x00\x01\x00", $data, 4) == 0) { // ICO
return "ico";
} else if (strncmp("\x89PNG\x0d\x0a\x1a\x0a", $data, 8) == 0) { // PNG
return "pmg";
} else if (strncmp('BM', $data, 2) == 0) { // BMP
return "bmp";
} else if (strncmp('GIF87a', $data, 6) == 0 || strncmp('GIF89a', $data, 6) == 0) { // GIF
return "gif";
} else if (strncmp("\xff\xd8", $data, 2) == 0) { // JPEG
return "jpg";
} else {
return NULL;
}
}
/*
* $files = $_FILES
* $formName = form tag name as <input type="file".... />
*/
function getUploadFiles($files,$formName,$prefix="img"){
$this->getUploadFileName = array();
for($i=0;$i<count($files[$formName]);$i++) {
$myrow = array(
'name' => $files[$formName]['name'][$i],
'type' => $files[$formName]['type'][$i],
'tmp_name' => $files[$formName]['tmp_name'][$i],
'error' => $files[$formName]['error'][$i],
'size' => intval($files[$formName]['size'][$i])
);
if ( $myrow['size']>0 ){
if ( !is_null($ext = $this->is_image($myrow['tmp_name'])) ){
$info = pathinfo($myrow['tmp_name']);
$upfile_name = $prefix . $this->getRandomString() . "." . $ext;
$upfile_path = XOOPS_ROOT_PATH."/uploads/" . $upfile_name;
move_uploaded_file($myrow['tmp_name'], $upfile_path);
chmod($upfile_path,0644);
$this->getUploadFileName[$i] = $upfile_name;
}
}
}
//var_dump($this->getUploadFileName); die;
return $this->getUploadFileName;
}
}
?>
2011年7月25日月曜日
Multiple fileupload class for Actung Baby
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿