PHP: Making thumbnail, why do i get these errors?
<p>When i made this function:</p>

<pre><code>function makeThumbnail($type, $name, $size, $tmp_name, $thumbSize) {

//make sure this directory is writable!

$path_thumbs = "uploaded_files/";       

//the new width of the resized image, in pixels.

$img_thumb_width = $thumbSize; // 

$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 -&gt; variables
$file_type = $type;

$file_name = $name;

$file_size = $size; 

$file_tmp = $tmp_name;
//check if you have selected a file.
echo $file_tmp."&lt;br&gt;";
echo $file_name."&lt;br&gt;";
echo $file_type."&lt;br&gt;";
echo $file_size."&lt;br&gt;";

if(!is_uploaded_file($file_tmp)){

echo "Error: Please select a file to upload!. &lt;br&gt;--&lt;a href=\"$_SERVER[PHP_SELF]\"&gt;back&lt;/a&gt;";

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") &amp;&amp; (!in_array($ext,$limitedext))) {

echo "Wrong file extension.  &lt;br&gt;--&lt;a href=\"$_SERVER[PHP_SELF]\"&gt;back&lt;/a&gt;";

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&gt;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!

imagecopyresampled($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", 100);

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 "OK THUMB " . $thumbSize;

exit();

//*/



//and you should be set!



//success message, redirect to main page.       

$msg = urlencode("$title was uploaded! &lt;a href=\"Resize.php\"&gt;Upload More?&lt;/a&gt;");
}
</code></pre>

<p>Then it stopped working, but outside a function, it works good.</p>

<p>As you can see i added "echo $file...." because i wanted to see if they have value, and they do have the right values.</p>

<p>I just get the error Error: Please select a file to upload.</p>

<p>This function is running after an normal upload image script(full size).</p>

<p>When i call the function i do:</p>

<pre><code>makeThumbnail($_FILES[$fieldname]['type'], $_FILES[$fieldname]['name'], $_FILES[$fieldname]['size'], $_FILES[$fieldname]['tmp_name'], 100);
</code></pre>

<p>At my other file where its not in a function, theres no difference only that the variables is:</p>

<pre><code>$file_type = $_FILES['file']['type'];

$file_name = $_FILES['file']['name'];

$file_size = $_FILES['file']['size'];

$file_tmp = $_FILES['file']['tmp_name'];
</code></pre>

<p>But it should work, I cant find anything wrong, but it doesnt and i keep getting that error. If i remove the is_uploaded_file function, i get a bunch of another errors.</p>
