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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:39:10+00:00 2026-06-14T18:39:10+00:00

I want to add image in directory. The directory makes dynamically. But there is

  • 0

I want to add image in directory. The directory makes dynamically. But there is an error while uploading the image in directory and image can’t upload due to this error the error is given below:

Warning: mkdir(): File exists in C:\wamp\www\test\index.php on line 21

My code is here:

 <body>
            <form method="post" action="" enctype="multipart/form-data">
            <input type="file" name="filename" id="filename" />
            <input type="submit" name="pic" />
            </form>

    </body>
    </html>

    <?php
        if(isset($_POST['pic'])){
            $comimages = $_FILES['filename']['tmp_name'];
            $targetpath = mkdir("pageimage/pageid");
                $compath = $targetpath."/".$_FILES['filename']['name'];

                $comFileType=$_FILES['filename']['type'];
                $comFileSize=$_FILES['filename']['size'];
                $comFileSize=$comFileSize/1024;

                if($comFileSize<1000)
                {
                    $arrFileType=array("image/jpeg","image/png","image/gif","image/bmp");

                    if(in_array($comFileType,$arrFileType))

                    {

                        move_uploaded_file($comimages,$compath);
                    }
                    else
                    {
                        echo("invalid file format");    
                    }
                }
                else
                {
                    echo("File Size Error");    
                }
        }
    ?>
  • 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-14T18:39:11+00:00Added an answer on June 14, 2026 at 6:39 pm

    The clue is in the error. The directory you are trying to create with $targetpath = mkdir("pageimage/pageid"); already exists… so you can’t make it again!

    I would suggest doing a quick file exists check before trying to make it. There is a function for that: file_exists()

    Also, mkdir() returns a boolean (success or fail); not a file directory, so you won’t be able to use your $targetpath variable as you expect.

    Try this instead…

    $targetpath = "pageimage/pageid";
    if (!file_exists($targetpath)) {
        mkdir($targetpath);
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add multiple borders on a single image. Is this possible through
Hi I want to add image in table cell according to condition in table.
I want to add an image, instead of the default button. I already have
I want to add background image to uinavigationcontroller. Please help me.
I want to add an image to be a background of the header, the
I want to add a background image to a bar chart using Highcharts and
I am very new to Java, I want to add a PNG image to
Hi an developing drawing android application. in that i want to add a sticker(image)
i want to add images or labels with image in it to a panel
I want to add a link to every image in the HTML with the

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.