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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:28:32+00:00 2026-05-14T00:28:32+00:00

Hallo I want to make an file upload. The script should take the image,

  • 0

Hallo
I want to make an file upload. The script should take the image, resize it and upload it.
But it seems that there is any unknown to me error in the upload.

Here the code

define ("MAX_SIZE","2000");     // maximum size for uploaded images
  define ("WIDTH","107"); // width of thumbnail
  define ("HEIGHT","107"); // alternative height of thumbnail (portrait 107x80)
  define ("WIDTH2","600"); // width of (compressed) photo
  define ("HEIGHT2","600"); // alternative height of (compressed) photo (portrait 600x450)

  if (isset($_POST['Submit'])) {
    // iterate thorugh all upload fields
    foreach ($_FILES as $key => $value) {

      //read name of user-file
      $image = $_FILES[$key]['name'];
      // if it is not empty
      if ($image) {
        $filename = stripslashes($_FILES[$key]['name']);  // get original name of file from clients machine
        $extension = getExtension($filename); // get extension of file in lower case format
        $extension = strtolower($extension);

        // if extension not known, output error
        // otherwise continue
        if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
          echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Unbekannter Dateityp: Es können nur Dateien vom Typ .gif, .jpg oder .png hochgeladen werden.</div>';
        } else {
          // get size of image in bytes
          // $_FILES[\'image\'][\'tmp_name\'] >> temporary filename of file in which the uploaded file was stored on server
          $size = getimagesize($_FILES[$key]['tmp_name']);
          $sizekb = filesize($_FILES[$key]['tmp_name']);

          // if image size exceeds defined maximum size, output error
          // otherwise continue
          if ($sizekb > MAX_SIZE*1024) {  
            echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Die Datei konnte nicht hochgeladen werden: die Dateigröße überschreitet das Limit von 2MB.</div>';
          } else {
            $rand = md5(rand() * time());  // create random file name
            $image_name = $rand.'.'.$extension;   // unique name (random number)

            // new name contains full path of storage location (images folder)
            $consname = "photos/".$image_name;  // path to big image
            $consname2 = "photos/thumbs/".$image_name;  // path to thumbnail

            $copied = copy($_FILES[$key]['tmp_name'], $consname);
            $copied = copy($_FILES[$key]['tmp_name'], $consname2);

            $sql="INSERT INTO photos (galery_id, photo, thumb) VALUES (". $id .", '$consname', '$consname2')" or die(mysql_error());
            $query = mysql_query($sql) or die(mysql_error());

            // if image hasnt been uploaded successfully, output error
            // otherwise continue
            if (!$copied) {
              echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Die Datei konnte nicht hochgeladen werden.</div>';
            } else {
              $thumb_name = $consname2;   // path for thumbnail for creation & storage
              // call to function: create thumbnail
              // parameters: image name, thumbnail name, specified width and height
              $thumb = make_thumb($consname,$thumb_name,WIDTH,HEIGHT);
              $thumb = make_thumb($consname,$consname,WIDTH2,HEIGHT2);
            }
          }
        }
      }
    }
    // current image could be uploaded successfully
    echo '<div class="success">'. $success .' Foto(s) erfolgreich hochgeladen!</div>';
    showForm();   // call to function: create upload form 
  }
  • 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-14T00:28:32+00:00Added an answer on May 14, 2026 at 12:28 am

    Can we see the PHP error log?


    Actually the message:
    ‘photos/03be646900419daa11eaa1d1af1fd024.jpg’ is not a valid JPEG file

    is saying it! The file is not a valid JPEG, this is the problem.

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

Sidebar

Related Questions

Hallo, i need to write some javascript that gets the contents of a userfield
I've written a small hello world test app in Silverlight which i want to
What I want is, I think, relatively simple: > Bin = <<Hello.world.howdy?>>. > split(Bin,
If given the route: {FeedName}/{ItemPermalink} ex: /Blog/Hello-World If the item doesn't exist, I want
I have the following string: <SEM>electric</SEM> cu <SEM>hello</SEM> rent <SEM>is<I>love</I>, <PARTITION />mind I want
Hallo, i am using WSS 3.0 and i need to display certain entries of
Hallo i am currently playing around with castle projects ActiveRecord and the remoting facility.
I.e.: echo H#97llo | MagicPerlCommand Stdout: Hallo were MagicPerlCommand is something like perl -pnle
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET

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.