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

  • Home
  • SEARCH
  • 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 7438179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:30:49+00:00 2026-05-29T10:30:49+00:00

I am using the following code, upload.php, to try to have someone upload a

  • 0

I am using the following code, upload.php, to try to have someone upload a picture that saves in a directory i have created (profile_images) and directs the filename to my database:

    <?php

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

//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("upload_picture_fileinput/jpg", "upload_picture_fileinput/jpeg", "upload_picture_fileinput/bmp", "upload_picture_fileinput/gif", "upload_picture_fileinput/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 = "insert into users (profile_image_filename) values ('" . $upload_picture_fileinput['name'] . "')";   


    $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;

    }

This is the relevant code for the page where the user is prompted to upload a picture:

<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";
            $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());

            while ($row = mysql_fetch_assoc($result)) {

                echo "<p>";

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


            }
        ?>

I am connecting to the database fine. The form for the image upload is named upload_picture_fileinput.

However, I continue to receive the error that I create: “You must upload a jpeg, gif, bmp, or png”;

The image is not saving to the my directory, nor is the filename uploaded to my database.

even though I am using one of these types. Please let me know if you see a problem.

  • 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-29T10:30:49+00:00Added an answer on May 29, 2026 at 10:30 am

    You have to modify your function is_valid_type as bellow.

    //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/pjpeg", "image/jpeg", "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp");
    
        if (in_array($file['type'], $valid_types))
            return 1;
        return 0;   
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have upload the video on facebook using following code Help From : https://github.com/zoul/facebook-ios-sdk/
I'm looking for the correct way of using wp_get_attachment_image(). The following code: <?php $args
I am using the following code to upload an image to a web server
I am using the following code to upload a video to Youtube through youtube
I am using the following code: <?php $token = $_REQUEST['token']; $file = $_REQUEST['file']; $sig
I am initializing file upload using the following HTML: <form enctype=multipart/form-data action=PHPScripts/upload.php method=POST> <input
A tutorial I'm following created a form using the code below. The teacher's form
I am trying to upload file to rackspace cloud file using the following code:
i've created a folder in my c drive (c:/artwork) that im using to upload
When I upload files in Yii using the following code it generates an error.

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.