have a script which i found online,through google for uploading and resizing photos when they are uploaded.
It works well,the only problem is that there are some images when i upload them they are not detected as a file,but others are uploaded well.
for example image of this properties is not detected.
(Dimension:3264*2448
camera model,DSC-W150
type:JPEG Image.
size:2,70 MB.
)
below is the script:

<?php
$user=$_SESSION['user'];

if(isset($_POST['submit']))
	{
	include"config.php";
		
		
		
		//make sure this directory is writable!
		$path_thumbs ='C:/wamp/www/website/thumb/';
		
		//the new width of the resized image, in pixels.
		$img_thumb_width = 120; // 

		$extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
		//List of allowed extensions if extlimit = yes
		$limitedext = array(".gif",".jpg",".png",".JPG",".JPEG",".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)){
           echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>";
           exit(); //exit the script and don't process the rest of it!
        }
       //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 "Wrong file extension.  <br>--<a href=profilephoto.php>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);
       //the new width variable
       $ThumbWidth = $img_thumb_width;

	   //////////////////////////
	   // CREATE THE THUMBNAIL //
	   //////////////////////////
	   
       //keep image type
       if($file_size){
          if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
               $new_img = imagecreatefromjpeg($file_tmp);
           }elseif($file_type == "image/x-png" || $file_type == "image/png"){
               $new_img = imagecreatefrompng($file_tmp);
           }elseif($file_type == "image/gif"){
               $new_img = imagecreatefromgif($file_tmp);
           }
           //list the width and height and keep the height ratio.
           list($width, $height) = getimagesize($file_tmp);
           //calculate the image ratio
           $imgratio=$width/$height;
            if ($imgratio>1){
              $newwidth = $ThumbWidth;
              $newheight = $ThumbWidth/$imgratio;
           }else{
                 $newheight = $ThumbWidth;
                 $newwidth = $ThumbWidth*$imgratio;
           }
           //function for resize image.
           if (function_exists(imagecreatetruecolor)){
           $resized_img = imagecreatetruecolor($newwidth,$newheight);
           }else{
                 die("Error: Please make sure you have GD library ver 2+");
           }
           //the resizing is going on here!
           imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
           //finally, save the image
           ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
           ImageDestroy ($resized_img);
           ImageDestroy ($new_img);
           
           
        }

        //ok copy the finished file to the thumbnail directory
		move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext");
		/*
			Don't want to copy it to a separate directory?
			Want to just display the image to the user?
			Follow the following steps:
			
			2. Uncomment this code:
		/*
		/* UNCOMMENT THIS IF YOU WANT */
		//echo "IMG:<img src=\"$path_big/$rand_name.$file_ext\" />";
		//exit();
		//*/
		
		//and you should be set!
             
		//success message, redirect to main page.		
		//$msg = urlencode("$rand_name.$file_ext was uploaded! <a href=\"Resize.php\">Upload More?</a>");
			//header("Location: Resize.php?msg=$msgn
			include"myprofile.php";
			
			include"config.php";
			$query="UPDATE login SET photo='$rand_name.$file_ext' WHERE user='$user'";
			$result=mysql_query($query);
			$check="UPDATE profile SET photos='$rand_name.$file_ext' WHERE users='$user'";
			$jibu=mysql_query($check);
			if(!$result||!$jibu){
			echo"failed to send to database";
			}
			
			
			
			
			
			
			
			
			exit();
		
	
}else{
	
		//if there is a message, display it
		if(isset($_GET['msg']))
		{
			//but decode it first!
			echo "<p>".urldecode($_GET['msg'])."</p>";
		}
		//the upload form
	
	
}


?>

this line here is the one return errors.

//check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a>";
           exit(); //exit the script and don't process the rest of it!
        }

i need your suggestions,what i should change here?
bcoz this is the biggest problem i`m experiencing.

Recommended Answers

All 9 Replies

Try changing the upload_max_filesize in php.ini . The default filesize for upload is 2mb.

i changed the value to
upload_max_filesize = 5M
but the problem is still there...
i`m totally comfused..

Hmm.. Try printing out $_FILES .. Check if $_FILES is set ! I tested your script with image size varying from 1 mb to 4 mb. Works fine :-/

i did as you said,and i got error displaying a number which equals to one(1).
down is how did.. check if i`m right..

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

//check if you have selected a file.
        if(!is_uploaded_file($file_tmp)){
           echo "Error: Please select a file to upload!. <br><a href=profilephoto.php>back</a><br>";
		   echo"$error";
           exit(); //exit the script and don't process the rest of it!
        }

Well, that error number corresponds to the max_file_size in php.ini . http://in2.php.net/manual/en/features.file-upload.errors.php ! Are you sure you changed the correct php.ini file (and restarted apache ?) :S I can't think of anything else other than the max file size.

thankx nav33n for ur contribution,me too i can`t thinkanymore of this issue.....
coz now i change the value
from

post_max_size = 8M
upload_max_filesize = 2M
max_execution_time = 30
max_input_time = 60
memory_limit = 8M

Change to:
post_max_size = 750M
upload_max_filesize = 750M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M

but nothing changed...

Lets see if someone else can solve this for you :-/

I remember I had a similar problem, and did all the changes suggested here, but the script actually only worked after I restarted the machine (my machine was relocated...so it was a complete restart)...

hope this helps!!!

ok!i will take a look,thankx.
Also if you check my Code in these line

$imgratio=$width/$height;
            if ($imgratio>1){
              $newwidth = $ThumbWidth;
              $newheight = $ThumbWidth/$imgratio;
           }else{
                 $newheight = $ThumbWidth;
                 $newwidth = $ThumbWidth*$imgratio;
           }

pictures are not in a good Ratio,some appears distorted.
if there is something i can change to make the appearance of the photos nice please Tell me.
i`ll appreciate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.