/** Forandever @ 2005/03/14
* Image Upload. The original file name is used by default.
* Uploaddir: Server Path
* Is_over: overwrite allowed
* $ Srcfile: name of the file Field
* $ New_name: Any name without a suffix
* Return Array
*/
Function uploadpic ($ uploaddir, $ file_src, $ new_name, $ is_over = 0)
{
$ File_tmp = getimagesize ($ _ FILES [$ file_src] ['tmp _ name']);
/* Type */
If ($ file_tmp ['mime ']! = 'Image/gif'
& $ File_tmp ['mime ']! = 'Image/jpg'
& $ File_tmp ['mime ']! = 'Image/JPEG'
& $ File_tmp ['mime ']! = 'Image/PNG'
& $ File_tmp ['application/X-Shockwave-flash']
){
Exit ('file format is not required. Only GIF, JPG/JPEG, and PNG formats can be uploaded! ');
}
Else
{
/* Width * height */
$ File_width = $ file_tmp ['0'];
$ File_height = $ file_tmp ['1'];
}
/* Size */
$ Filesize = sizecount ($ _ FILES [$ file_src] ['SIZE']);
/* Ext */
$ Ext = substr (strrchr (TRIM (strtolower ($ _ FILES [$ file_src] ['name']), "."), 1 );
/* Name */
If ($ new_name = "")
{
$ Last_name = $ _ FILES [$ file_src] ['name'];
}
Else
{
$ Last_name = $ new_name. ".". $ ext;
}
/* Array */
$ Pic_arr = array (
Newname => $ last_name,
Lastname => $ _ FILES [$ file_src] ['name'],
Width => $ file_width,
Height => $ file_height,
Size => $ filesize,
EXT => $ Ext,
Mime => $ file_tmp ['mime ']
);
/* Check database */
$ Pname = $ pic_arr [newname];
$ P_showname = $ pic_arr [lastname];
$ Pwidth = $ pic_arr [width];
$ Pheight = $ pic_arr [height];
$ Psize = $ pic_arr [size];
$ Ext = $ pic_arr [ext];
$ Que = "select count (PID) from pic_view where p_showname = '$ p_showname' and pwidth =' $ pwidth' and pheight = '$ pheight' and psize = '$ psize '";
$ Res = mysql_query ($ que );
If (0 <> mysql_num_rows ($ res ))
{
Exit ("Sorry! The same file already exists on the server! ");
}
/* If exists */
If ($ is_over = 0)
{
If (file_exists ($ uploaddir. $ _ FILES [$ file_src] ['name'])
{
Exit ("the file you uploaded already exists! ");
}
Else
{
If (move_uploaded_file ($ _ FILES [$ file_src] ['tmp _ name'], $ uploaddir. $ last_name ))
{
Return $ pic_arr;
}
}
}
Else
{
If (move_uploaded_file ($ _ FILES [$ file_src] ['tmp _ name'], $ uploaddir. $ last_name ))
{
Return $ pic_arr;
}
}
}