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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:12:45+00:00 2026-05-29T11:12:45+00:00

I am trying to resize an image that I have uploaded with a form.

  • 0

I am trying to resize an image that I have uploaded with a form. I am using the script scene here: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

I am also using the following code to upload the image:

upload.php:

    <?php

    session_start();
    require_once "database.php";
    db_connect();
    require_once "auth.php";
    $current_user = current_user();

    $emailstring = $current_user['email'];

//Check to see if the type of file uploaded is a valid image type
function is_valid_type($file)
{
    //This is an array that holds all the valid image MIME types
    $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png");

    if (in_array($file['type'], $valid_types))
        return 1;
    return 0;   

}

function showContents($array) 
    {

        echo "<pre>";
        print_r($array);
        echo "</pre>";
    }

//Set some constants

//This variable is the path to the image folder where all the images are going to be stored

//Note that there is a trailing forward slash
$TARGET_PATH = "profile_images/";

//Get our POSTed variables
$upload_picture_fileinput = $_FILES['upload_picture_fileinput'];


//Sanitize input
$upload_picture_fileinput['name'] = mysql_real_escape_string($upload_picture_fileinput['name']);

//Build our target path full string.  This is where the file will be moved to
//i.e. profile_images/picture.jpg
$TARGET_PATH .= $upload_picture_fileinput['name'];

if(!is_valid_type($upload_picture_fileinput)) {

    $_SESSION['error'] = "You must upload a jpeg, gif, bmp, or png";
    header("Location: account.php");
    exit;


    }

//attempt to move the file from its temporary directory to its new home
if (move_uploaded_file($upload_picture_fileinput['tmp_name'], $TARGET_PATH)) {

    $sql = "UPDATE `users` SET `profile_image_filename`='" . $upload_picture_fileinput['name'] . "'
                       WHERE email='$emailstring'";


    $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());

    header("Location: account.php");
    exit;
}
else 
{


    $_SESSION['error'] = "Could not upload file.  Check read/write permissions on the directory";
    header("Location: account.php") ;
    exit;

    }

and where my form is:

<div class="pictures add_pictures">
            <div class="add_picture">
                <div class="upload_picture">
                    <form action="upload.php" method="POST" enctype="multipart/form-data" name="upload_picture_form" class="upload_picture_form">
                        <span class="add_picture_label">+ Add a Profile Picture</span>
                        <input type="file" name="upload_picture_fileinput" class="upload_picture_file_input"/>
                        <input type="hidden" name="MAX_FILE_SIZE" value="100000"/>
                        <br><br><br><br><br><br><br>

                        <input type="submit" id="submit" value="Upload" />
                    </form>
                </div>
            </div>
        </div>

        <?php

            $sql = "select * FROM `users` WHERE `id`='$id'";
            $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());



                $row = mysql_fetch_assoc($result);


                echo "<p>";

                echo "<img src=\"profile_images/" . $row['profile_image_filename'] . "\" alt=\"\" /><br />";
                echo "</p>";



        ?>
                                    //not currently working
                <img src="/imageresize.php"/>

The echo above prints the picture out fine, but when I try to use that filename to resize the image, it does not appear/work.

<?php
    session_start();
    require_once "database.php";
    db_connect();
    require_once "auth.php";
    $current_user = current_user();

    $resized_image = '\"profile_images/" . $row['profile_image_filename'] . "\" alt=\"\" /';

    header('Content-Type: image/jpg');
    include('SimpleImage.php');
    $image = new SimpleImage();
    $image->load($resized_image);
    $image->resizeToWidth(300);
    $image->output();


?>

I am connecting to the database fine and the image filename is being saved in my database. I just don’t know why the file path above will print the picture, but not work in the resize script. Please help if you can. Thank you.

  • 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-29T11:12:46+00:00Added an answer on May 29, 2026 at 11:12 am

    Looks like in $resized_image you have added the html alt tag which should, of course, not be part of the parameter you are feeding into $image->load($resized_image);.

    Try changing this to

    $image->load('profile_images/' . $row['profile_image_filename']);
    

    instead of the string that already targets the html rendering.

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

Sidebar

Related Questions

I'm trying to resize an image that is uploaded to Drupal via a form.
I'm trying to resize an image in Silverlight 3 that has been submitted by
Really, really trying to find a plugin that gives adds functionality to the image-resize
I am trying to resize the image using javascript, but I am getting errors
Basically I am inserting an image using the listviews inserting event, trying to resize
I'm trying to build the simple layout that I have got in the image
I am trying to resize an image using only CSS, the problem is I
I am trying to resize an image before it gets saved. I am using
I have a resize script i made in PHP that uses GD (my VPS
I'm trying to place an image panel on a form such that when a

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.