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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:39:01+00:00 2026-06-15T14:39:01+00:00

Trying to use the following scripts to upload, resize & save multiple images via

  • 0

Trying to use the following scripts to upload, resize & save multiple images via a form. It’s not working… not even stripped down to one input and foreach removed. I’ve tried combining the upload & resize scripts and then redirecting the form action to the combined script. Can’t get that to work. Now trying to move the uploaded file from upload.php to SimpleImage.php using move_uploaded_file but it doesn’t seem to be working either. Not getting any errors just blank pages.
I will add better validation later, just trying to get it to work now.
Sorry for so much code, just wanted to have all of it here for your reference.

My questions:
How to I get upload.php to send the image to the resize script or should it be vise versa? any ideas on why it’s not working or showing errors?

I’m new to php but am very determined to figure this out! I’ll take any and all advice &/or insults you can throw at me! I learn from both! 🙂 Thanks in advance!!!

the form:

<?php
   if( isset($_POST['submit']) ) {

      include('SimpleImage.php');
      $image = new SimpleImage();
      $image->load($_FILES['uploaded_image']['tmp_name']);
      $image->resizeToWidth(500);
      $image->save("uploads/uploadedfiles/".$pictures);
   } else {

?>

<form action="/upload.php" method="post" enctype="multipart/form-data"></br>

<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br /> 
<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br /> 
<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br /> 
<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br /> 
<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br /> 
<input type="file" name="uploaded_image[]" accept="image/gif, image/jpeg, image/png" /> <br />    <br />  
<input type="hidden" name="MAX_FILE_SIZE" value="48000000" /> *Images must be no more than     5MB.<br /> .jpg, .gif &amp; .png files accepted only.<br /><br />
<input type="submit" value="Upload"> </p> </form>

upload.php:

<?php


header("Location:confirmationpage.php");

foreach ($_FILES["pictures"]["error"] as $key => $error) {
  if (($_FILES["pictures"]["type"] == "image/gif")
  || ($_FILES["pictures"]["type"] == "image/jpeg")
  || ($_FILES["pictures"]["type"] == "image/png" )
  && ($_FILES["pictures"]["size"] < 50000))
   {
       move_uploaded_file(
         $_FILES["pictures"]["tmp_name"][$key],     "/SimpleImage.php" . $_FILES["pictures"]["name"][$key]); 
   }
}
 ?>

the resize script (SimpleImage.php):

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/

class SimpleImage {

   var $image;
   var $image_type;

   function load($uploaded_image) {

  $image_info = getimagesize($uploaded_image);
  $this->image_type = $image_info[2];
  if( $this->image_type == IMAGETYPE_JPEG ) {

     $this->image = imagecreatefromjpeg($uploaded_image);
  } elseif( $this->image_type == IMAGETYPE_GIF ) {

     $this->image = imagecreatefromgif($uploaded_image);
  } elseif( $this->image_type == IMAGETYPE_PNG ) {

     $this->image = imagecreatefrompng($uploaded_image);
  }
   }
   function save($uploaded_image, $image_type=IMAGETYPE_JPEG, $compression=75,     $permissions=null) {

  if( $image_type == IMAGETYPE_JPEG ) {
     imagejpeg($this->image,$uploaded_image,$compression);
  } elseif( $image_type == IMAGETYPE_GIF ) {

     imagegif($this->image,$uploaded_image);
  } elseif( $image_type == IMAGETYPE_PNG ) {

     imagepng($this->image,$uploaded_image);
  }
  if( $permissions != null) {

     chmod($uploaded_image,$permissions);
  }
   }
   function output($image_type=IMAGETYPE_JPEG) {

  if( $image_type == IMAGETYPE_JPEG ) {
     imagejpeg($this->image);
  } elseif( $image_type == IMAGETYPE_GIF ) {

     imagegif($this->image);
  } elseif( $image_type == IMAGETYPE_PNG ) {

     imagepng($this->image);
  }
   }
   function getWidth() {

  return imagesx($this->image);
   }
   function getHeight() {

  return imagesy($this->image);
   }
   function resizeToHeight($height) {

  $ratio = $height / $this->getHeight();
  $width = $this->getWidth() * $ratio;
  $this->resize($width,$height);
   }

   function resizeToWidth($width) {
  $ratio = $width / $this->getWidth();
  $height = $this->getheight() * $ratio;
  $this->resize($width,$height);
   }

   function scale($scale) {
  $width = $this->getWidth() * $scale/100;
  $height = $this->getheight() * $scale/100;
  $this->resize($width,$height);
   }

   function resize($width,$height) {
  $new_image = imagecreatetruecolor($width, $height);
  imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this-        >getWidth(), $this->getHeight()); 
  $this->image = $new_image;
   }      

}
?>
  • 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-15T14:39:02+00:00Added an answer on June 15, 2026 at 2:39 pm

    Okay So we’ve all been new, and newness is kinda always around. The First thing is this attempt to move an image into a php file…
    what happens is when your script is called it’s parsed, compiled and executed(basically, but generally) so this move image into script is not going to work so far as I understand. you need to write a script that instantiates an instance of the simpleImage class and calls methods of that class(now object), with the uploaded image in question passed as a parameter to the methods you want to use.

    instantiate simple image…

      $imgWrk = new simpleImage;
    

    use simple image…

       $imgWrk->load($var)
    

    so that’s the first bit, there are specifics as regards the simpleImage API (application programming Interface( in this case interface suffices)) which you should become more familiar with. the second bit regards the script you will have written in which you instantiate the simple image class. you will need to, with your uploaded file move it to a directory(assuming you want to store images whether or not you edit them) and then in this script you will have written something title like ownImageEdit.php(or whatever) you would create a variable whose value would be a handle for this uploaded image and that would be the variable you pass into the simpleImage object methods.

    Now my answer is somewhat general because a worthwhile solution to this problem would involve code refactoring that you will ultimately have to do, which involves more than you realize, and somewhat more than this questions answer will allow.

    you need to understand php’s OOP, as well as how php scripts get executed. Learn to love the manual.

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

Sidebar

Related Questions

I am trying to use the multiple upload attribute of HTML5 to upload files.
I'm trying to use the following scripts so that the result of the first
I am trying to use the following script in asp.net: <script language=javascript type=text/javascript> function
Trying to use the following demo example, using the 80px x 80px snap to
I am trying to use the following jcache-ehcache library to as a wrapper so
I am trying to use the following code, to display $formcode, which is the
I'm trying to use the following code # LOAD XML FILE $XML = new
I'm trying to use the following code to make an image fadeOut and, only
I'm trying to use the following code and it still strips out all the
I'm trying to use the following code (poorly written, but it's just a proof

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.