Autor Tema: Crne slike  (Pročitano 653 puta)

Laky

  • Medior
  • ***
  • Poruke: 121
    • Blog
Crne slike
« poslato: 02.08.2013 19:19:57 »
<?php

function Upload1($ime1)
{
error_reporting(0);

$change="";
$abc="";


 define ("MAX_SIZE","400");
 function getExtension($str) {
 $i strrpos($str,".");
 if (!$i) { return ""; }
 $l strlen($str) - $i;
 $ext substr($str,$i+1,$l);
 return $ext;
 }

 $errors=0;
  
 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
$image $ime1.".png";
$uploadedfile $_FILES['upload1']['tmp_name'];
 
 
if ($image
{

$filename stripslashes($ime1.".png");

$extension getExtension($filename);
$extension strtolower($extension);


 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
{

$change='<div class="msgdiv">Unknown Image extension </div> ';
$errors=1;
}
else
{

 $size=filesize($_FILES['upload1']['tmp_name']);


if ($size MAX_SIZE*1024)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
$errors=1;
}


if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile $_FILES['upload1']['tmp_name'];
$src imagecreatefromjpeg($uploadedfile);

}
else if($extension=="png")
{
$uploadedfile $_FILES['upload1']['tmp_name'];
$src imagecreatefrompng($uploadedfile);

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

echo $scr;

list($width,$height)=getimagesize($uploadedfile);


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


$newwidth1=128;
$newheight1=93;
$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);


$filename "images/"$ime1.".png";

$filename1 "images/small"$ime1.".png";



imagejpeg($tmp,$filename,100);

imagejpeg($tmp1,$filename1,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
}
}

}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors
 {

 }
}


?>


<html>
<head>

  </head>
  <body>

    <form method="post" action="" enctype="multipart/form-data" name="form1">

<input type='file' name='upload1'><br/>
<input type='file' name='upload2'><br/>
<input type='file' name='upload3'><br/>
<input type='file' name='upload4'><br/>
<input type='file' name='upload5'><br/>
 
  <input type='submit' name='submit'>

</form>


<?php

$submit = @$_POST['submit'];

if($submit)
{

$ime=date("d/m/y").time("H:M:S");
$ime=md5($ime);

$ime1 $ime '1';


$datum=date("d/m/y");
$vrijeme=time("H:M:S");
$ime=$datum.$vrijeme;
$ime=md5($ime);


$ime1=NULL;


$uploaded_file1=basename(@$ime1.".png");



if($uploaded_file1!=NULL){
$ime1=$ime.'1';
}


if($uploaded_file1 !=NULL){
Upload1($ime1);
}

}

?>

 
 
 

   
</body>
</html>


Moze li neko provjerit zasto mi pravi crne slike ? :)

PS. ne obracajte paznju na ove ostale type='file'   jer samo radim sa tim jednim upload1   :) 

milica

  • Administrator
  • Novajlija
  • *****
  • Poruke: 45
Odg: Crne slike
« Odgovor #1 poslato: 06.08.2013 23:52:50 »
<?php

function Upload1($ime1)
{
error_reporting(0);

$change="";
$abc="";


 define ("MAX_SIZE","400");
 function getExtension($str) {
 $i strrpos($str,".");
 if (!$i) { return ""; }
 $l strlen($str) - $i;
 $ext substr($str,$i+1,$l);
 return $ext;
 }

 $errors=0;
  
 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
$image $ime1.".png";
$uploadedfile $_FILES['upload1']['tmp_name'];
 
 
if ($image
{

$filename stripslashes($ime1.".png");

$extension getExtension($filename);
$extension strtolower($extension);


 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
{

$change='<div class="msgdiv">Unknown Image extension </div> ';
$errors=1;
}
else
{

 $size=filesize($_FILES['upload1']['tmp_name']);


if ($size MAX_SIZE*1024)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
$errors=1;
}


if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile $_FILES['upload1']['tmp_name'];
$src imagecreatefromjpeg($uploadedfile);

}
else if($extension=="png")
{
$uploadedfile $_FILES['upload1']['tmp_name'];
$src imagecreatefrompng($uploadedfile);

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

echo $scr;

list($width,$height)=getimagesize($uploadedfile);


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


$newwidth1=128;
$newheight1=93;
$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);


$filename "images/"$ime1.".png";

$filename1 "images/small"$ime1.".png";



imagejpeg($tmp,$filename,100);

imagejpeg($tmp1,$filename1,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
}
}

}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors
 {

 }
}


?>


<html>
<head>

  </head>
  <body>

    <form method="post" action="" enctype="multipart/form-data" name="form1">

<input type='file' name='upload1'><br/>
<input type='file' name='upload2'><br/>
<input type='file' name='upload3'><br/>
<input type='file' name='upload4'><br/>
<input type='file' name='upload5'><br/>
 
  <input type='submit' name='submit'>

</form>


<?php

$submit = @$_POST['submit'];

if($submit)
{

$ime=date("d/m/y").time("H:M:S");
$ime=md5($ime);

$ime1 $ime '1';


$datum=date("d/m/y");
$vrijeme=time("H:M:S");
$ime=$datum.$vrijeme;
$ime=md5($ime);


$ime1=NULL;


$uploaded_file1=basename(@$ime1.".png");



if($uploaded_file1!=NULL){
$ime1=$ime.'1';
}


if($uploaded_file1 !=NULL){
Upload1($ime1);
}

}

?>

 
 
 

   
</body>
</html>


Moze li neko provjerit zasto mi pravi crne slike ? :)

PS. ne obracajte paznju na ove ostale type='file'   jer samo radim sa tim jednim upload1   :)

Prvo, bolje izbaci getExtension() da ti je dostupna svudje, znaci van Upload1() funkcije. Drugo, debaguj da li su ti putanje fajlova dobre. I uvijek drzi error_reporting ukljucen tokom developmenta da bi vidio potencijane greske koje ti uzrokuju problem. Vjerovatno ces ovdje vidjeti gdje ti je greska kad enablujes reporting. Ukloni error_reporting(0); i stavi na sami vrh koda sljedece:
ini_set('display_errors',1);
error_reporting(E_ALL);

milica

  • Administrator
  • Novajlija
  • *****
  • Poruke: 45
Odg: Crne slike
« Odgovor #2 poslato: 07.08.2013 00:00:34 »
Doduse, sad probah tvoj kod i kod mene radi bez problema jedino sto imas jedan typo dje si pogrijesio ime varijable (linija 74). Vidji je li ti GD library instalirana da valja.