$updir = $_SERVER["DOCUMENT_ROOT"]."/test/upload"; // Definer stien til dit oploadbibliotek $aft = array('image/jpeg','image/pjpeg','image/png'); // De filtyper der kan uploades
/* Function checkgd() checks the version of gd, and returns "yes" when it's higher than 2 */ function checkgd(){ $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2'){$gd2="yes";} return $gd2; }
/* Function ditchtn($arr,$thumbname) filters out thumbnails */ function ditchtn($arr,$thumbname){ foreach ($arr as $item){ if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;} } return $tmparr; }
/* Function createthumb($name,$filename,$new_w,$new_h) creates a resized image variables: $name Original filename $filename Filename of the resized image $new_w width of resized image $new_h height of resized image */ function createthumb($name,$filename,$new_w,$new_h){ global $gd2; $system=explode(".",$name); echo $name." :name<br />"; echo $system[4]." :system[4]<br />";
if (preg_match("/jpg|jpeg/",$system[4])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[4])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2==""){ $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); }else{ $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])){ imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
/* Function directory($directory,$filters) reads the content of $directory, takes the files that apply to $filter and returns an array of the filenames. You can specify which files to read, for example $files = directory(".","jpg,gif"); gets all jpg and gif files in this directory. $files = directory(".","all"); gets all files. */ function directory($dir,$filters){ $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all"){ $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f<sizeof($filters);$f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; }
if (empty($_REQUEST['fil'])) { echo "Du skal vælge en fil"; } else {
if (in_array($_FILES['fil']['type'],$aft)) { if (move_uploaded_file($_FILES['fil']['tmp_name'], $newfilename)) { $gd2=checkgd(); createthumb($newfilename,$updir."/"."thumb_".$newfilename,100,100);
$imginfo = getimagesize($newfilename); $imgwidth = $imginfo[0]; //bredde i pixels $imgheight = $imginfo[1]; //højde i pixels $imgtype = $imginfo[2]; //jpg, gif, bmp osv $imghtml = $imginfo[3]; //height="yyy" width="xxx" - for use directly in html Echo "Alt OK<br />"; Echo $_REQUEST['tekst']; } else {} } else { echo "Filtypen er ikke korrekt!"; } }
Warning: imagejpeg: unable to open '/customers/silkeborgbasketball.dk/silkeborgbasketball.dk/httpd.www/test/upload/thumb_/customers/silkeborgbasketball.dk/silkeborgbasketball.dk/httpd.www/test/upload/1_Vinter.jpg' for writing in /customers/silkeborgbasketball.dk/silkeborgbasketball.dk/httpd.www/test/test3.php on line 77 Alt OK
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
I mit oprindelige script uploadede jeg filen med sit originale navn. I det tilfælde var $newfilename = $updir."/".$_FILES['fil']['name']; og jeg lavede min thumb med følgende kald: createthumb($_FILES['fil']['name'],$updir."/"."thumb_".$_FILES['fil']['name'],100,100);
Det virkede uden problemer.
Det jeg gerne vil er, at rename den til "$galleri_filnavn" (fx'1_billede.jpg'), hvilket jeg godt kan gøre. Men når jeg så prøver at lave min thumb går det galt, som du kan se.
Stien du henviser til kommer af: $updir."/"."thumb_".$newfilename hvor jeg prøver at fortælle scriptet at jeg ønsker at få min thumb navngivet 'thumb_filnavn' (fx 'thumb_1_billede.jpg')
hmm.. den er svær at se. af en eller anden grund tror scriptet at thumb_ er en mappe. måske er der et / for meget, eller $updir sættes forkert eller en gang for meget..
$updir = $_SERVER["DOCUMENT_ROOT"]."/test/upload"; // Definer stien til dit oploadbibliotek $aft = array('image/jpeg','image/pjpeg','image/png'); // De filtyper der kan uploades
/* Function checkgd() checks the version of gd, and returns "yes" when it's higher than 2 */ function checkgd(){ $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2'){$gd2="yes";} return $gd2; }
/* Function ditchtn($arr,$thumbname) filters out thumbnails */ function ditchtn($arr,$thumbname){ foreach ($arr as $item){ if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;} } return $tmparr; }
/* Function createthumb($name,$filename,$new_w,$new_h) creates a resized image variables: $name Original filename $filename Filename of the resized image $new_w width of resized image $new_h height of resized image */ function createthumb($name,$filename,$new_w,$new_h){ global $gd2; $system=explode(".",$name); echo $name." :name<br />"; echo $system[4]." :system[4]<br />";
if (preg_match("/jpg|jpeg/",$system[4])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[4])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2==""){ $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); }else{ $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])){ imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
/* Function directory($directory,$filters) reads the content of $directory, takes the files that apply to $filter and returns an array of the filenames. You can specify which files to read, for example $files = directory(".","jpg,gif"); gets all jpg and gif files in this directory. $files = directory(".","all"); gets all files. */ function directory($dir,$filters){ $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all"){ $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f<sizeof($filters);$f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; }
if (empty($_REQUEST['fil'])) { echo "Du skal vælge en fil"; } else {
if (in_array($_FILES['fil']['type'],$aft)) { if (move_uploaded_file($_FILES['fil']['tmp_name'], $newfilename)) { $gd2=checkgd(); createthumb($newfilename, $newthumb,100,100);
$imginfo = getimagesize($newfilename); $imgwidth = $imginfo[0]; //bredde i pixels $imgheight = $imginfo[1]; //højde i pixels $imgtype = $imginfo[2]; //jpg, gif, bmp osv $imghtml = $imginfo[3]; //height="yyy" width="xxx" - for use directly in html Echo "Alt OK<br />"; Echo $_REQUEST['tekst']; } else {} } else { echo "Filtypen er ikke korrekt!"; } }
Jeg har ryddet lidt ud i mit script, da jeg opdagede at der var nogle ting der stammede fra et andet projekt. Desuden har jeg lavet tvunget lowercase. Min endelige fil ser således ud:
$updir = "upload/"; // Definer stien til dit oploadbibliotek $aft = array('image/jpeg','image/pjpeg','image/png'); // De filtyper der kan uploades
/* Function checkgd() checks the version of gd, and returns "yes" when it's higher than 2 */ function checkgd(){ $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2'){$gd2="yes";} return $gd2; }
/* Function createthumb($name,$filename,$new_w,$new_h, $updir) creates a resized image variables: $name Original filename $filename Filename of the resized image $new_w width of resized image $new_h height of resized image */ function createthumb($name,$filename,$new_w,$new_h,$updir){
global $gd2; $system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2==""){ $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); }else{ $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])){ imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
if (empty($_REQUEST['fil'])) { echo "Du skal vælge en fil"; } else {
if (in_array($_FILES['fil']['type'],$aft)) { if (move_uploaded_file($_FILES['fil']['tmp_name'], $newfilename)) { $gd2=checkgd(); createthumb($newfilename, $newthumb,100,100,$updir);
$imginfo = getimagesize($newfilename); $imgwidth = $imginfo[0]; //bredde i pixels $imgheight = $imginfo[1]; //højde i pixels $imgtype = $imginfo[2]; //jpg, gif, bmp osv $imghtml = $imginfo[3]; //height="yyy" width="xxx" - for use directly in html Echo "Alt OK<br />"; Echo $_REQUEST['tekst']; } else {} } else { echo "Filtypen er ikke korrekt!"; } }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.