Jump to content
php.lv forumi

Melnas bildes pie uploada


Cibiņš

Recommended Posts

Kapēc pie uploada resizējot bildi tā tiek pārvietota kā melna bilde??

 

<?php

$uploadedfile = $_FILES['userfile']['tmp_name'];
$filename = stripslashes($_FILES['userfile']['name']);

if(isset($_FILES['userfile']['tmp_name'])){
    function getExtension($str) {
    	$i = strrpos($str,".");
    	if (!$i) { return ""; }
    	$l = strlen($str) - $i;
    	$ext = substr($str,$i+1,$l);
    	return $ext;
}

$extension = getExtension($filename);
$extension = strtolower($extension);
list($width,$height)=getimagesize($uploadedfile);


$newwidth=60;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);

$newwidth1=25;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

$flnm = substr(md5($_FILES['userfile']['name'].microtime().rand(1,100000)),0,30);
$filename = "./". $flnm.'.'.$extension;
$filename1 = "./small". $flnm.'.'.$extension;

imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
echo "success";
} else {
 echo "error";
}
?>

Link to comment
Share on other sites

Ieslēdz, lai rāda notices un warningus, tad, gan jau, sapratīsi kāpēc. Jo pagaidām, tu tur izveido 2 melnas bildes un tādas viņas arī saglabā. Ko satur $src?

 

Piedod, šodien esmu āzis :D Paldies, izlaidu cauri erroru debugerim un tieši dēļ tā src viņš dzina ārā melnas bildes. :)

 

Šitais te pietrūka

 

if($extension=="jpg" || $extension=="jpeg" )
   {
   $src = imagecreatefromjpeg($uploadedfile);

   }
   else if($extension=="png")
   {
   $src = imagecreatefrompng($uploadedfile);

   }
   else {
  	 $src = imagecreatefromgif($uploadedfile);
   }

Edited by Cibiņš
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...