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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:17:16+00:00 2026-06-04T10:17:16+00:00

This is what I am trying to accomplish. I need the users to be

  • 0

This is what I am trying to accomplish.
I need the users to be able to load a picture and show it on their profile page. There is one table on my sql database named “members” with fields as follow, username, password, firstname, lastname, photo.
All fields except photo are completed on the registration form. Once users go to their profile page they will find a form to upload a picture to their profile.
I got this code for the upload_form.php.. (code listed bellow) and another file upload_processor.php (code listed after)

This code successfully load the file into my folder uploaded_files and it renames the file to something like this… 1140732936-filename.jpg to ensure the file is unique.
How can I get the name of 1140732936-filename.jpg saved into my “photo” field on my sql table? Is there any way? Help please….

Code for the upload_form

    <?php

    // filename: upload.form.php

    // first let's set some variables

    // make a note of the current working directory relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '',     $_SERVER['PHP_SELF']);

    // make a note of the location of the upload handler script
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self .   'upload.processor.php';

    // set a max file size for the html upload form
    $max_file_size = 3000000; // size in bytes

    // now echo the html page
    ?>

Here is the html form on the same file

<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">

    <h1>
        Upload form
    </h1>

    <p>
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
    </p>

    <p>
        <label for="file">File to upload:</label>
        <input id="file" type="file" name="file">
    </p>

    <p>
        <label for="submit">Press to...</label>
        <input id="submit" type="submit" name="submit" value="Upload me!">
    </p>

</form>


</body>

Here is the code for the file that process the form.

    <?php

    // filename: upload.processor.php

    // first let's set some variables

    // make a note of the current working directory, relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

    // make a note of the directory that will recieve the uploaded file
    $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';

    // make a note of the location of the upload form in case we need it
    $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'updateprofile.php';

    // make a note of the location of the success page
    $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';

    // fieldname used within the file <input> of the HTML form
    $fieldname = 'file';

    // Now let's deal with the upload

    // possible PHP upload errors
    $errors = array(1 => 'php.ini max file size exceeded',
            2 => 'html form max file size exceeded',
            3 => 'file upload was only partial',
            4 => 'no file was attached');

    // check the upload form was actually submitted else print the form
    isset($_POST['submit'])
    or error('the upload form is neaded', $uploadForm);

    // check for PHP's built-in uploading errors
    ($_FILES[$fieldname]['error'] == 0)
    or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

    // check that the file we are working on really was the subject of an HTTP upload
    @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
    or error('not an HTTP upload', $uploadForm);

    // validation... since this is an image upload script we should run a check  
    // to make sure the uploaded file is in fact an image. Here is a simple check:
    // getimagesize() returns false if the file tested is not an image.
    @getimagesize($_FILES[$fieldname]['tmp_name'])
    or error('only image uploads are allowed', $uploadForm);

    // make a unique filename for the uploaded file and check it is not already
    // taken... if it is already taken keep trying until we find a vacant one
    // sample filename: 1140732936-filename.jpg
    $now = time();
    while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
     $now++;
    }
    // now let's move the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
    or error('receiving directory insuffiecient permission', $uploadForm);

    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' . $uploadSuccess);

    // The following function is an error handler which is used
    // to output an HTML error page if the file upload fails
    function error($error, $location, $seconds = 5)
    {   
    header("Refresh: $seconds; URL=\"$location\"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
    '<html lang="en">'."\n".
    '    <head>'."\n".
    '        <meta http-equiv="content-type" content="text/html; charset=iso-   8859-1">'."\n\n".
    '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
    '    <title>Upload error</title>'."\n\n".
    '    </head>'."\n\n".
    '    <body>'."\n\n".
    '    <div id="Upload">'."\n\n".
    '        <h1>Upload failure</h1>'."\n\n".
    '        <p>An error has occured: '."\n\n".
    '        <span class="red">' . $error . '...</span>'."\n\n".
    '         The upload form is reloading</p>'."\n\n".
    '     </div>'."\n\n".
    '</html>';
    exit;
    } // end error handler

    ?>
  • 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-04T10:17:18+00:00Added an answer on June 4, 2026 at 10:17 am

    In the page upload_processor.php
    Add some SQL just after the image is copied to server.
    I have no code therfore iam supposing you have generating image name with microtime().
    Save generated image name in a variable called $variable .Then rename the image with that variable and

       <?php
    
        // filename: upload.processor.php
    
        // first let's set some variables
    
        // make a note of the current working directory, relative to root.
        $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
    
        // make a note of the directory that will recieve the uploaded file
        $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
    
        // make a note of the location of the upload form in case we need it
        $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'updateprofile.php';
    
        // make a note of the location of the success page
        $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';
    
        // fieldname used within the file <input> of the HTML form
        $fieldname = 'file';
    
        // Now let's deal with the upload
    
        // possible PHP upload errors
        $errors = array(1 => 'php.ini max file size exceeded',
                2 => 'html form max file size exceeded',
                3 => 'file upload was only partial',
                4 => 'no file was attached');
    
        // check the upload form was actually submitted else print the form
        isset($_POST['submit'])
        or error('the upload form is needed', $uploadForm);
    
        // check for PHP's built-in uploading errors
        ($_FILES[$fieldname]['error'] == 0)
        or error($errors[$_FILES[$fieldname]['error']], $uploadForm);
    
        // check that the file we are working on really was the subject of an HTTP upload
        @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
        or error('not an HTTP upload', $uploadForm);
    
        // validation... since this is an image upload script we should run a check  
        // to make sure the uploaded file is in fact an image. Here is a simple check:
        // getimagesize() returns false if the file tested is not an image.
        @getimagesize($_FILES[$fieldname]['tmp_name'])
        or error('only image uploads are allowed', $uploadForm);
    
        // make a unique filename for the uploaded file and check it is not already
        // taken... if it is already taken keep trying until we find a vacant one
        // sample filename: 1140732936-filename.jpg
        $now = time();
        while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
        {
         $now++;
        }
        // now let's move the file to its final location and allocate the new filename to it
        @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or error('receiving directory insuffiecient permission', $uploadForm);
    
        // If you got this far, everything has worked and the file has been successfully saved.
        // We are now going to redirect the client to a success page.
        //connect database
        mysql_query("update members set photo='".$uploadFilename."' where member_id='".$_SESSION['id']."'");
    
        header('Location: ' . $uploadSuccess);
    
        // The following function is an error handler which is used
        // to output an HTML error page if the file upload fails
        function error($error, $location, $seconds = 5)
        {   
        header("Refresh: $seconds; URL=\"$location\"");
        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
        '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
        '<html lang="en">'."\n".
        '    <head>'."\n".
        '        <meta http-equiv="content-type" content="text/html; charset=iso-   8859-1">'."\n\n".
        '        <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
        '    <title>Upload error</title>'."\n\n".
        '    </head>'."\n\n".
        '    <body>'."\n\n".
        '    <div id="Upload">'."\n\n".
        '        <h1>Upload failure</h1>'."\n\n".
        '        <p>An error has occured: '."\n\n".
        '        <span class="red">' . $error . '...</span>'."\n\n".
        '         The upload form is reloading</p>'."\n\n".
        '     </div>'."\n\n".
        '</html>';
        exit;
        } // end error handler
    
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to accomplish this: Consider a table view with Search Bar on
I'm trying to accomplish the following using CSS: <table border=1 width=300px> <tr> <td rowspan=2>This
I'm trying to determine if there is a way to accomplish this elegantly. I
I'm trying to accomplish this: strcat('red ', 'yellow ', 'white ') I expected to
I'm trying to accomplish what's being demonstrated at this site for an experiment I'm
I am stuck with using Dojo to accomplish this. Basically what I am trying
I'm trying to get my application to show the url as follows: example.com/42/jessica-alba This
For few days now I'm trying to solve this problem. I have table group_user,
What I'm trying to accomplish is the following: I need to limit the amount
Alright, I am trying to accomplish this: When a user clicks a button that

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.