Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML/PHP File Upload
    text
    copied!<p>So i want the user to only be able to upload docs or docx's. So first here's my html:</p> <pre><code>&lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt; Select a file: &lt;input type="file" name="img"&gt; &lt;input type="submit"&gt; &lt;/form&gt; </code></pre> <p>And here's my php:</p> <pre><code>$allowedExts = array("doc", "docx"); $extension = end(explode(".", $_FILES["file"]["name"])); if ($extension!=".doc" || $extension!=".doc" &amp;&amp; ($_FILES["file"]["size"] &lt; 200000) &amp;&amp; in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] &gt; 0) { echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;"; } else { echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;"; echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;"; if (file_exists("Proposals/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "Proposals/" . $_FILES["file"]["name"]); echo "Stored in: " . "Proposals/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } </code></pre> <p>Everytime I try to upload a file, whether it's a doc or a png it outputs this:</p> <pre><code>Upload: Type: Size: 0 Kb Temp file: already exists. </code></pre> <p>And nothing ends up getting uploaded to the Proposals folder. So I have 2 questions:<br> 1) what is the problem with my code?<br> 2) it redirects to upload_file.php and displays a message. Is there a way to actually go back the main page and display text that it was successful?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload