Created
January 22, 2015 12:23
-
-
Save sandeepwisetr/c611bda35fb2db0813c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function file_upload($f, $folder) { | |
extract($f); | |
echo("<pre>"); | |
print_r($f); | |
echo("</pre>"); | |
//echo($f["photo"]["type"]); | |
$name = $f["photo"]["name"]; | |
$tmp_name = $f["photo"]["tmp_name"]; | |
$size = $f["photo"]["size"]; | |
$type = $f["photo"]["type"]; | |
//$extension=array("image/png","image/jpg","image/gif"); | |
if ($type == "image/png" || $type == "image/jpg" || $type == "image/gif" || $type == "image/jpeg") { | |
$ext = end(explode(".", $name)); | |
; | |
$encname = substr(md5($name), 0, 8) . "." . $ext; | |
if ($folder == "") { | |
$folder = date("d_m_y"); | |
$folder = "gallery/" . $folder; | |
if (!file_exists($folder)) { | |
mkdir($folder); | |
} | |
} | |
$path = $folder . "/" . $encname; | |
$a = move_uploaded_file($tmp_name, $folder . "/" . $encname); | |
if ($a) { | |
$ginert = $this->insertquery("insert into gallery (gid,name,encname,size,path) values('','$name','$encname','$size','$path') ", "file_upload"); | |
if ($ginert) { | |
return mysql_insert_id(); | |
} | |
} else { | |
echo("error"); | |
} | |
} else { | |
echo("unknown file type"); | |
} | |
} | |
/* | |
just pass global array of $_FILES or your cutomize array with temp file | |
$f=arrray(); | |
$f=$_FILES; //(file name should photo means $_FILES["photo"]["name"] ); | |
$folder="user_upload"; | |
file_upload($f, $folder) | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment