, but works in PHP 4.3
Pleaaaaaaaaaaase HELP!
My code is: (Somewhere there are comments in Croatian I will translate them if necessary
if (isset($HTTP_POST_VARS['imagefile'])){
$imagefile=$HTTP_POST_VARS['imagefile'];
}
//////SLIKA
$uploaddir = "slike3//";
if(strlen($imagefile_name)>0)
{
$pext = getFileExtension($imagefile_name); ///fFunkcije.php
$pext = strtolower($pext);
if (strcmp($pext, "jpg")!=0 && strcmp($pext, "jpeg")!=0)
{
$greska = $greska. "Nedozvoljeni format datoteke, primaju se samo JPG slike<br/>";
echo $greska;
/*== delete uploaded file ==*/
unlink($imagefile);
}
else {
/////VECA SLIKA
$imgsize = getimagesize($imagefile);
////dali ju treba resizeat
if (($imgsize[0] > 235) || ($imgsize[1] > 176))
{
$width = $imgsize[0];
$height = $imgsize[1];
$width2 = 235;
$height2 = 176;
if ($width > $width2)
{
$factor = $width2 / $width;
$width = $width2;
$height = $height * $factor;
}
if($height > $height2)
{
$factor = $height2 / $height;
$height = $height2;
$width = $factor * $width;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($imagefile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $imgsize[0], $imgsize[1]);
imagejpeg($image_p, $imagefile);
}
$logo = str_replace(" ", "_", $imagefile_name);
$logo = stringZaSliku($uploaddir,$logo,1);
if (is_uploaded_file($imagefile))
{
if (!copy($imagefile,"$logo"))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
$greska = $greska. "<br>Error Uploading File.</br>";
exit();
}
}
else
{
$greska = $greska. "<br>Error Uploading File.</br>";
}
}
unlink($imagefile);
}
function stringZaSliku($uploaddir,$logo,$v){
$i=0;
$l = strtolower($logo);
for($i=0;$l[$i+3]!='\0';$i++){
if($l[$i]=='.' && $l[$i+1]=='j' && $l[$i+2]=='p' &&($l[$i+3]=='g' || $l[$i+4]=='g'))
break;
}
if($v==1) $ret = $uploaddir."".substr($logo,0,$i)."".danasDatum().".jpg";
else $ret = $uploaddir."v".substr($logo,0,$i)."".danasDatum().".jpg";
return $ret;
}I rewrited the whole script and it worked. Thank God!
Pleaaaaaaaaaaase HELP!
My code is: (Somewhere there are comments in Croatian I will translate them if necessary
if (isset($HTTP_POST_VARS['imagefile'])){
$imagefile=$HTTP_POST_VARS['imagefile'];
}
//////SLIKA
$uploaddir = "slike3//";
if(strlen($imagefile_name)>0)
{
$pext = getFileExtension($imagefile_name); ///fFunkcije.php
$pext = strtolower($pext);
if (strcmp($pext, "jpg")!=0 && strcmp($pext, "jpeg")!=0)
{
$greska = $greska. "Nedozvoljeni format datoteke, primaju se samo JPG slike<br/>";
echo $greska;
/*== delete uploaded file ==*/
unlink($imagefile);
}
else {
/////VECA SLIKA
$imgsize = getimagesize($imagefile);
////dali ju treba resizeat
if (($imgsize[0] > 235) || ($imgsize[1] > 176))
{
$width = $imgsize[0];
$height = $imgsize[1];
$width2 = 235;
$height2 = 176;
if ($width > $width2)
{
$factor = $width2 / $width;
$width = $width2;
$height = $height * $factor;
}
if($height > $height2)
{
$factor = $height2 / $height;
$height = $height2;
$width = $factor * $width;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($imagefile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $imgsize[0], $imgsize[1]);
imagejpeg($image_p, $imagefile);
}
$logo = str_replace(" ", "_", $imagefile_name);
$logo = stringZaSliku($uploaddir,$logo,1);
if (is_uploaded_file($imagefile))
{
if (!copy($imagefile,"$logo"))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
$greska = $greska. "<br>Error Uploading File.</br>";
exit();
}
}
else
{
$greska = $greska. "<br>Error Uploading File.</br>";
}
}
unlink($imagefile);
}
function stringZaSliku($uploaddir,$logo,$v){
$i=0;
$l = strtolower($logo);
for($i=0;$l[$i+3]!='\0';$i++){
if($l[$i]=='.' && $l[$i+1]=='j' && $l[$i+2]=='p' &&($l[$i+3]=='g' || $l[$i+4]=='g'))
break;
}
if($v==1) $ret = $uploaddir."".substr($logo,0,$i)."".danasDatum().".jpg";
else $ret = $uploaddir."v".substr($logo,0,$i)."".danasDatum().".jpg";
return $ret;
}I rewrited the whole script and it worked. Thank God!