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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:17:51+00:00 2026-05-30T17:17:51+00:00

I am trying to upload various images into a dynamically created folder on my

  • 0

I am trying to upload various images into a dynamically created folder on my server, then take each image and resize it while uploading it into the folder as well creating a new image and a new name.. example: image.jpg (original image) and image-resized.jpg (being the thumbnail image).

The thing I can not figure out is how to resize all images. I am not sure if I should put it in a loop. All I need is for each image I upload (could be 5 a time). It loops through and resizes them all and not just a single image. Here is my code any help would be appreciated!

Code to create folders and move picture into those folders:

// Desired folder structure
        $structure = './Fotos/'.$newfolder;

        // To create the nested structure, the $recursive parameter 
        // to mkdir() must be specified.

        if (!mkdir($structure, 0, true)) {
        die('Failed to create folders...');
}else{
    $placefoldername = mysql_query("INSERT INTO datefolders (FolderDate) VALUES ('$newfolder')") or die(mysql_error());
    echo "<div class=\"success\">El folder fue agregado con exito.<input type=\"button\" name=\"close\" value=\"X\" class=\"close\" /></div>";
    }}

// ...

    }

if(isset($_POST['upload'])){
    $FolderDate = $_POST['fecha-folder'];
    $FolderName = $_POST['FolderName'];
    $hour = $_POST['hour'];

        // Desired folder structure
        $structure = './Fotos/'.$FolderDate.'/'.$hour.'/'.$FolderName;

        // To create the nested structure, the $recursive parameter 
        // to mkdir() must be specified.


        for($i=0;$i<count($_FILES['fileupload']['name']);$i++) {
            $names = $_FILES['fileupload']['name'][$i];
            $target_path = "Fotos/".$FolderDate."/".$hour."/".$FolderName."/";

            $target_path = $target_path . basename( $_FILES['fileupload']['name'][$i]); 

            if(move_uploaded_file($_FILES['fileupload']['tmp_name'][$i], $target_path)) {
             $success = 1;

Code to create a smaller (resized image) and also place into the already created folder:

$img = $names;   
        $imgPath = $structure;


        function resizeImage($img, $imgPath, $suffix, $by, $quality)
{
    //Create a thunbnail image by resizing the picture
    // Open the original image.
    $original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original (<em>$imgPath/$img</em>)");
    list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");

    // Determine new width and height.
    $newWidth = ($width/$by);
    $newHeight = ($height/$by);

    // Resample the image.
    $tempImg = imagecreatetruecolor($newWidth, $newHeight) or die("Cant create temp image");
    imagecopyresized($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");

    // Create the new file name.
    $newNameE = explode(".", $img);
    $newName = ''. $newNameE[0] .''. $suffix .'.'. $newNameE[1] .'';

    // Save the image.
    imagejpeg($tempImg, "$imgPath/$newName", $quality) or die("Cant save image");

    // Clean up.
    imagedestroy($original);
    imagedestroy($tempImg);
    return true;
}
$resize = resizeImage($img, $imgPath, "-resized", 23, 100);
  • 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-30T17:17:52+00:00Added an answer on May 30, 2026 at 5:17 pm

    Why are you defining the function resizeImage in the for loop? It is being redefined every time the loop iterates. This could be part of the problem. Define the function outside the loop and see if that works.

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

Sidebar

Related Questions

I am trying to Upload image Capture by Camera into server. server send response
I'm trying to upload an image from android to a PHP server by using
I am trying to upload image files to the server and it gives me
I am trying to upload an image to a server along with some JSON
I'm trying to build JPG upload functionality into our Windows Phone app. The server-side
I'm trying to upload an image to my site through a form, however it's
i am trying to upload an image from a jsp page using servlet. but
I'm currently trying to upload a picture to a server with the FileTransfer.upload() method
been trying to upload music onto a server for my website, to no avail,
Trying to upload a photo rendered on my server to the facebook album of

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.