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 8220335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:29:17+00:00 2026-06-07T13:29:17+00:00

How i can detect spoiled images after upload? Im using some code like this:

  • 0

How i can detect spoiled images after upload?

Im using some code like this:

$imageSize = getimagesize($tmp_name);
if(!$imageSize ||  !in_array($imageSize['mime'], $allowMimeType)){
    $this->error = 'Bad Image';
    @unlink($tmp_name);
    return false;
}
$tn = imagecreatetruecolor(80, 80);
switch ($imageSize['mime']){
    case 'image/jpeg':
        $userphoto = imagecreatefromjpeg($tmp_name);// Error 1
    break;
    case 'image/png':
        $userphoto = imagecreatefrompng($tmp_name);// Error 1
    break;
    case 'image/gif':
        $userphoto = imagecreatefromgif($tmp_name);// Error 1
    break;
    case 'image/bmp':
        $userphoto = imagecreatefromwbmp($tmp_name);// Error 1
    break;
    default:
        $this->error = 'unknown image';
        @unlink($tmp_name);
        return false;
    break;
}
imagecopyresampled($tn, $userphoto, 0, 0, 0, 0, 80, 80, $width, $height);// Error 2
imagejpeg($tn,'images/userphoto/'.$this->username.'.jpg',100);
chmod('images/userphoto/'.$this->username.'.jpg', 0777);
@unlink($tmp_name);
USERPROFILE::updatePhotoByUsersId($this->username.'.jpg', $this->users_id);

But some time i give 2 error tandem,

  1. at lines that have comment // Error 1

imagecreatefromwbmp() [href=’function.imagecreatefromwbmp’>function.imagecreatefromwbmp]: >’images/userphoto/4ff7db9800871.bmp’ is not a valid WBMP file

imagecreatefromgif() [href=’function.imagecreatefromgif’>function.imagecreatefromgif]: >’images/usersphoto/4fe70bb390758′ is not a valid GIF file

  1. at line of comment // Error 2

    imagecopyresampled(): supplied argument is not a valid Image resource

I think its occurs because the file has damaged during uploading. If i’m right, how i can solve this problem? If not, What is the reason?

  • 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-06-07T13:29:18+00:00Added an answer on June 7, 2026 at 1:29 pm

    Before you do any further processing, you should check the return value of getimagesize() .

    If getimagesize() returns a FALSE, that means it has failed and something is wrong with the file, so you should terminate. Once the image passes this check, you can continue with your processing.

    As for why you are getting supplied argument is not a valid Image resource, the explaination is simple: Most likely, the image stored in $userphoto is actually FALSE because imagecreatefrompng() and other imagecreatefrom functions have failed, returning a FALSE.

    Solution: Check that the uploaded image is valid with getimagesize() before continuing.

    Some possible reasons as to why the uploads are failing:

    • Something is corrupting the images when they are written to the temp directory.
    • User is uploading corrupted files.

    Regarding imagecreatefromwbmp() failing, it is because gd does not support BMP files. You need to convert the BMP into a format gd can work with. For example, you can use bmp2png.

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

Sidebar

Related Questions

I would like to write some C++ program that can detect the presence of
I'm looking for .NET static code analysis tools that can detect things like unit
I know I can detect a single backspace keypress like this: $(#myelement).bind (keyup, function(event)
I can detect that app is running under iOS Simulator (using sysctlbyname(hw.machine) ), but
I know that richtextboxes can detect links (like http://www.yahoo.com ) but is there a
Is there a way I can detect an image URL, like: http://mysite.com/image.jpg but with
I'd like to find a tool that can detect redundant/unused tables and stored procedures
Is there a php or javascript code that can detect the current user's page
How can detect the keyboard key down and trigger this line? $('#submit_p').live('click',function(event){...} Thanks.
Is there a code snippet that can detect the current user's page and then

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.