Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1027993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:19:07+00:00 2026-05-16T12:19:07+00:00

When i made this function: function makeThumbnail($type, $name, $size, $tmp_name, $thumbSize) { //make sure

  • 0

When i made this function:

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

$file_name = $name;

$file_size = $size; 

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

if(!is_uploaded_file($file_tmp)){

echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[PHP_SELF]\">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=\"$_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);

//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!

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! <a href=\"Resize.php\">Upload More?</a>");
}

Then it stopped working, but outside a function, it works good.

As you can see i added “echo $file….” because i wanted to see if they have value, and they do have the right values.

I just get the error Error: Please select a file to upload.

This function is running after an normal upload image script(full size).

When i call the function i do:

makeThumbnail($_FILES[$fieldname]['type'], $_FILES[$fieldname]['name'], $_FILES[$fieldname]['size'], $_FILES[$fieldname]['tmp_name'], 100);

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

$file_type = $_FILES['file']['type'];

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

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

$file_tmp = $_FILES['file']['tmp_name'];

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:19:07+00:00Added an answer on May 16, 2026 at 12:19 pm

    Make sure you are not using move_uploaded_file() before calling the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this function to verify a user's twitter credentials. Its running on two
Hi have made this function which is made to replicate an error that I
I made this little function from code snippets around the net. It does what
I made this simple function to filter the data. I add the symbols that
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
I've made this snippet that clicks a link after 10th second: function timeout() {
I made a fancy shape with OpenGL and I draw that shape this function:
It made some errors like this: KDnsCache.cpp: In member function ‘unsigned int KDnsCache::GetName(const char*)’:
I made a user-define function for business hours calculation. This is my UDF. CREATE
I have made this function, that seems to work fine, but it return #

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.