Jump to content

[SOLVED] No error but image is not saved


EagerWolf

Recommended Posts

I have tried to create image-resizer. I've checked everything by know... chmod to my path is OK, but my picture isn't uploaded. Please help me!

 

Form.php is php because it's going to be changed later :)

 

File: form.php

<form action="uploader.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="25000">Upload Image: <input type="file" name="imgfile">
<font size="1">Click browse to upload a local file</font>
<input type="submit" value="Upload Image">
</form>

 

 

File: uploader.php

<?php
if(isset($_POST['submit']))
{		
	$path = "picture"; //Ime direktorija kamor shranjujemo!

	//Dolocimo velikost slike
	$framed_img_h = 330;
	$framed_img_w = 330;

	$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
	//List of allowed extensions if extlimit = yes
	$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");

	//the image -> variables
    $file_type = $_FILES['vImage']['type'];
        $file_name = $_FILES['vImage']['name'];
        $file_size = $_FILES['vImage']['size'];
        $file_tmp = $_FILES['vImage']['tmp_name'];

        //check if you have selected a file.
        if(!is_uploaded_file($file_tmp))
        {
           exit(); 
        }
       
        //check the file's extension
       $ext = strrchr($file_name,'.');
       $ext = strtolower($ext);
       //uh-oh! the file extension is not allowed!
       if (($extlimit == "yes") && (!in_array($ext,$limitedext))) 
       {
          echo "Napaka, format slike ni dovoljen!  <br>--<a href=\"$_SERVER[php_SELF]\">back</a>";
          exit();
       }
       //so, whats the file's extension?
       $getExt = explode ('.', $file_name);
       $file_ext = $getExt[count($getExt)-1];

       //create a random file name
       $rand_name = md5(time());
       $rand_name= rand(0,999999999);
       
   ///////////////////////////////////////
   // Naredimo okvirjeno sliko in ikono //
   ///////////////////////////////////////
   
       if($file_size)
       {
       	
		// Pogledamo velikost slike 
           $new_img = imagecreatefromjpeg($file_tmp);
           list($width, $height) = getimagesize($file_tmp);

           //Izracunamo razmerje slike
           $imgratio = $width / $height;
           
           
           if ($imgratio > 1) // Slika je podolgovata
           {
           		$newheight = $framed_img_h;
           		$newwidth = $newheight/$imgratio;
           }
           
           elseif ($imgratio < 1) //Slika je pokoncna
           {
           		$newwidth = $framed_img_w;
           		$newheight = $newwidth/$imgratio;
           }
           
           elseif ($imgratio == 1) //Slika je kvadratna
           {
           		$newwidth = $framed_img_w;
           		$newheight = $framed_img_h;
       }
           

           //Resize IMAGE
           
           //Najprej preverimo podporo streznika in se izognemo sesutju strani
           if (function_exists(imagecreatetruecolor))
           {
           		$resized_img = imagecreatetruecolor($newwidth,$newheight);
           }
           
           else
           {
                die("Error: Please make sure you have GD library ver 2+");
           }
           
           //Tukaj sliko ustrezno povecamo/pomanjsamo
           imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

           //Nato novo dobljeno sliko tudi shranimo!
           imagejpeg($resized_img,"$path/$rand_name.jpeg");

           ImageDestroy ($resized_img);
           ImageDestroy ($new_img);
           
           
        }

}
else 
{
header("Location: form.php");
}
?>

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/38376-solved-no-error-but-image-is-not-saved/
Share on other sites

$path =  "uploads/".basename( $_FILES['imgfile']['name']); 

  if(move_uploaded_file($_FILES['imgfile']['tmp_name'], $path)) 
  { 
    echo "file was uploaded";

} else{
    echo "error";
exit;
} 

Im not real sure about what all you are doing but the above code will store it in the uploads folder

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.