2

I have a problem about upload file using PHP in my local Windows Apache server.

My configuration:

  • Windows 10

Wamp Server with:

  • PHP 8.0
  • Apache 2.4.54.2

The target upload file size:

  • 9KB , which is a gif

What I have tried:

php.ini:

file_uploads = On

upload_tmp_dir ="G:/wamp64/tmp" <- This is another hard drive location, not wamp server's drive itself.

Apache httpd.conf:

 <Directory />
    AllowOverride All
    Allow from all
    Require local
 </Directory> 

I have used a html file to submit file like this:

   <form action="" method="post" enctype="multipart/form-data">
<p>
    <label>new brand</label>
    <input type="text" name="txt_brand_name_chi" id="txt_brand_name_chi" />
    <input type="file" name="pic_brand_img" id="pic_brand_img" />
    <input type="button" name="sbt_brand_name_chi" id="sbt_brand_name_chi" value="Add" />
</p>

Here is the code that receive file upload:

if(isset($_POST['txt_brand_name_chi']) && $_FILES['pic_brand_img']){
    $target_dir = "http://localhost/test/20250512/upload/";
    $target_file = $target_dir . basename($_FILES["pic_brand_img"]['name']);

    print_r($_FILES['pic_brand_img']);

    $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

    if (!is_writable($target_dir)) {
        echo "NOT writable";
        
    } 

    if(move_uploaded_file($_FILES["pic_brand_img"]["name"], $target_file))
        echo "OK";
    else
        echo "NO";
    

}

After that I receive brand info like this:

Result after submit file upload

This is the result after I submit the file to server through PHP:

Array ( [name] => logo.gif [type] => image/gif [tmp_name] => G:\wamp64\tmp\phpA230.tmp [error] => 0 [size] => 8790 )

I didn't find any problem, I guess the problem is in Apache, so I tried to change the folder permission in security tab, add "everyone" account and make it can access all permissions, but the result is still unsuccessful.

I have checked the modification date of the tmp folder, it has updated every time I run the PHP script, but the folder is empty, I don't know what's going wrong.

Folder didn't updated

How can I fix this problem?

1
  • Comments have been moved to chat; please do not continue the discussion here. Before posting a comment below this one, please review the purposes of comments. Comments that do not request clarification or suggest improvements usually belong as an answer, on Meta Stack Overflow, or in Stack Overflow Chat. Comments continuing discussion may be removed. Commented May 20 at 12:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.