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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:48:06+00:00 2026-06-12T08:48:06+00:00

I’m trying to upload a file so here’s my html: <form action=upload_file.php method=post enctype=multipart/form-data>

  • 0

I’m trying to upload a file so here’s my html:

<form action="upload_file.php" method="post" enctype="multipart/form-data">
    Select a file: <input type="file" name="upload">
    <input type="submit">
</form>

Here’s my php:

    <?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);
    session_start();
    $allowedExts = array("doc", "docx");
    $extension = pathinfo( $_FILES["upload"]["name"],PATHINFO_EXTENSION);

    if (($_FILES["upload"]["size"] < 200000)
    && in_array($extension, $allowedExts)) {
        if ($_FILES["upload"]["error"] > 0)
        {
            echo "Return Code: " . $_FILES["upload"]["error"] . "<br />";
        }
        else
        {
            echo "Upload: " . $_FILES["upload"]["name"] . "<br />";
            echo "Type: " . $_FILES["upload"]["type"] . "<br />";
            echo "Size: " . ($_FILES["upload"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["upload"]["tmp_name"] . "<br />";

            $dir_exists = is_dir("Proposals/". $_SESSION["FirstName"] ."/");
            $file_exists = file_exists("Proposals/".$_SESSION["FirstName"] ."/" . $_FILES["upload"]["name"]);
            $folderName=$_SESSION["FirstName"];
            $baseDir = "Proposals" ;
            //var_dump($_FILES);
            //die();
            // Create directory if it does not exist
            if (! $dir_exists) {
                if(!is_dir($baseDir))
                    mkdir($baseDir);
                mkdir($baseDir . DIRECTORY_SEPARATOR . $_SESSION["FirstName"]);
            } 

            if ($file_exists) {
                echo $_FILES["upload"]["name"] . " already exists. ";
            } else {
                move_uploaded_file($_FILES["upload"]["tmp_name"],
                "Proposals/". $_SESSION["FirstName"] ."/". $_FILES["upload"]["name"]);
                echo "Stored in: " . "Proposals/". $_SESSION["FirstName"] ."/". $_FILES["upload"]["name"];
            }
        }
    } else {
        echo "Invalid file";
    }

?>

The file outputted:

Type: application/msword
Size: 124.9296875 Kb
Temp file: /tmp/phpUWDc3s

The var_dump outputted this on a test file:

array(1) { ["upload"]=> array(5) { 
["name"]=> string(18) "Test.doc" 
["type"]=> string(18) "application/msword" 
["tmp_name"]=> string(14) "/tmp/phpUWDc3s" 
["error"]=> int(0) 
["size"]=> int(127928) } }

And the warnings/errors it gives me are:

Strict Standards: Only variables should be passed by reference in /disks/vhosts/***/***/upload_file.php on line 6 Upload: Test.doc

WITHOUT the mkdir code it gives me:

Warning: move_uploaded_file(Proposals/Test.doc): failed to open stream: Permission denied in /disks/vhosts/***/***/upload_file.php on line 40 Warning: move_uploaded_file(): Unable to move '/tmp/phpQmgxdO' to 'Proposals/Test.doc' in /disks/vhosts/***/***/upload_file.php on line 40 Stored in: Proposals/Test.doc

For some reason with or without the mkdir, no file is being put in the Proposals paper even if it’s the right file type. Is this just a permission issue with the server or is there something I have to add/change to make this all work?

  • 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-12T08:48:08+00:00Added an answer on June 12, 2026 at 8:48 am

    A. The first Error

    Strict Standards: Only variables should be passed by reference in /disks/vhosts///upload_file.php on line 6 Upload: Test.doc

    Change

      $extension = end(explode(".", $_FILES["upload"]["name"]));
    

    To

      $extension = path_info( $_FILES["upload"]["name"],PATHINFO_EXTENSION);
    

    B. The second error

    Warning: move_uploaded_file(Proposals/Test.doc): failed to open stream: Permission denied in /disks/vhosts///upload_file.php on line 40 Warning: move_uploaded_file(): Unable to move ‘/tmp/phpQmgxdO’ to ‘Proposals/Test.doc’ in /disks/vhosts///upload_file.php on line 40 Stored in: Proposals/Test.doc

    Use something like this with full path /disks/vhosts/***/***/

    $baseDir = __DIR__ ; // or /disks/vhosts/***/***/ has applicable 
    if (! $dir_exists) {
        if (is_writable("$baseDir/Proposals/")) {
            mkdir("$baseDir/Proposals/" . $_SESSION["FirstName"]);
        } else {
            trigger_error("Proposals/ is not writeable");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and

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.