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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:22:54+00:00 2026-06-16T10:22:54+00:00

hey guys im wondering on how to rename a file specially image before uploading

  • 0

hey guys im wondering on how to rename a file specially image before uploading it into the servers folder to avoid same name of the file when uploaded and rewrite the file with same name with it. i tend to use the school_id as a file name for the image. here is the php code

include_once('DBconnect.php');

session_start();
$school_id = $_SESSION['school_id'];


$name = $_FILES['file_path'] ['name'];
$size = $_FILES['file_path'] ['size'];
$type = $_FILES['file_path'] ['type'];

$extension = substr($name, strpos($name, '.')+1);

$max_size =3145728;

$temp_file = $_FILES['file_path'] ['tmp_name'];

if(isset($name)){

    if(!empty($name)){

        if(($extension == 'jpg' || $extension == 'jpeg') && ($type ==  'image/jpeg' || $type == 'image/jpg') && $size <= $max_size  ){



         if($school_id == 0){

            $location = 'uploads_images/super_admin/';





                                  move_uploaded_file($temp_file,$location.$name);

                     $insert_path = "INSERT INTO image_upload  (school_id,path_name) 
                                                     VALUES('$school_id','$name')";

                                $result2 = mysql_query($insert_path);
                                              if(@!$result2){
                                                    die('error header'.mysql_error());
                                                  }



                    echo "Success in uploading";


            }
            else{

                $location = 'uploads_images/schools/';




                                 move_uploaded_file($temp_file,$location.$name);

                     $insert_path = "INSERT INTO image_upload (school_id,path_name) 
                                        VALUES('$school_id','$name')";

                                        $result = mysql_query($insert_path);
                                          if(@!$result){
                                               die('error header'.mysql_error());
                                             }

                    echo "Success in uploading";





            }



        }
        else{

            echo "File type is too big or Incorrect file type";
        }


    }
    else{

            echo "Please Choose A JPEG File";
        }

}


?>
  • 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-16T10:22:56+00:00Added an answer on June 16, 2026 at 10:22 am

    Do not trust client side filename.

    You can pass new filename into move_uploaded_file function.
    I’d suggest you to do something like this:

    $name=uniqid($school_id, true).$extension;
    move_uploaded_file($temp_file,$location.$name);
    

    uniqid is built in php function http://php.net/manual/en/function.uniqid.php

    I hope this is helpful

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

Sidebar

Related Questions

Hey guys I was wondering how I could download a file that is generated
Hey guys I was wondering why my last script in this file isn't working
Hey guys I was wondering if someone could provide a little help. I've been
Hey guys I was wondering if anyone could help me with an issue im
Hey guys, i was wondering if you would help me a little with my
Hey guys, sorry for, but I'm new to doubly-linked lists and was wondering if
Hey guys i'm making my first game in c++ and I was wondering how
Hey guys! When I try to do the following in a header file static
Hey guys I was wondering how I would get the highest id in wordpress.
Hey guys. Just wondering if anyone knows of a method to create sparkline graphs

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.