Ja, jeg har et kodeforslag..
Function UploadImgHejn($user_ref,$content,$active="false"){
//-------------------------------------------------------------------------------------------------
global $HTTP_POST_FILES;
$allowed = array('jpg','png','jpeg','gif');
$str_ext = substr(strtolower (strrchr ($_FILES['userfile']['name'], '.')),1);
if($str_ext == 'gif'){
$str_ext = 'png';
$str_ext2 = 'gif';
}
$str_size = $_FILES["userfile"]["size"];
if (in_array(strtolower($str_ext),$allowed) && ($str_size < (ini_get('upload_max_filesize')*1024*1024)) && $str_size > 0) {
$strSQL = "INSERT INTO galleri (user_ref,active,content,str_ext)"
. "VALUES("
. "'" . $user_ref . "',"
. "'" . $active . "',"
. "'" . $content . "',"
. "'" . $str_ext . "'"
. ")";
mysql_query($strSQL) or die("Query failed [" . mysql_error() . "]");
$fileid = mysql_insert_id();
$path_to_file = $_SERVER["DOCUMENT_ROOT"] . "/galleri_billeder/";
$path_to_file = str_replace("//","/",$path_to_file);
$files = $_FILES['userfile'];
if(!is_dir($path_to_file)){
mkdir_p($path_to_file);
chmod($path_to_file,0755);
}
if (!ereg("/$", $path_to_file))
$path_to_file = $path_to_file."/";
if ($files['size']) {
$name=$fileid;
$location = $path_to_file . $name . "." . $str_ext;
$location_sub = $path_to_file . $name;
while (file_exists($location))
$location .= ".copy";
move_uploaded_file($files['tmp_name'],$location);
if($str_ext2 == 'gif'){
passthru("/usr/bin/gif2png -O $location");
}
chmod($location,0755);
$img = null;
if ($str_ext == 'jpg' || $str_ext == 'jpeg') {
$img = @imagecreatefromjpeg($location);
} else if ($str_ext == 'png') {
$img = @imagecreatefrompng($location);
}
$full_x = imagesx($img);
$full_y = imagesy($img);
imagedestroy($img);
$strSQL = "UPDATE plugin_imageviewer SET "
. "size_x = '" . $full_x . "',"
. "size_y = '" . $full_y . "' "
. "WHERE id = '" . $fileid . "'";
mysql_query($strSQL);
}
}
//-------------------------------------------------------------------------------------------------
}
Den er jo så lavet til en mysql database, hvor der allerede er oprettet forbindelse og en tabel der hedder plugin_imageviewer, men du kan jo bare rette den til som du vil..
Spørg endelig hvis der er noget du ikke forstår..
Indlæg senest redigeret d. 19.06.2006 22:44 af Bruger #7933