Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a few problems with your code.</p> <p>One of which is this: <code>&lt;input type="submit" name="commit" value="send"&gt;</code></p> <p>You checked if <code>if(isset($_POST['submit'])){</code> when your submit button was called <code>commit</code>; FAIL.</p> <p>Your <code>if (($thumbimage['size'] &gt; 350000) || ($mainmane['size'] &gt; 350000)) {</code> is wrong.</p> <p>It needs to be like this:</p> <p><code>if (($_FILES["newsthumb"]["size"] &gt; 350000) || ($_FILES["newsmain"]["size"] &gt; 350000)) {</code></p> <p>I replaced <code>$error[] = "One or Both of the files are too large.&lt;br&gt;";</code> with:</p> <pre><code>echo "One or Both of the files are too large.&lt;br&gt;"; exit; </code></pre> <p>The <code>$error</code> variable wasn't mentioned anywhere else and it didn't do anything, so I replaced it with an <code>echo</code> and an <code>exit;</code> to stop execution and not upload anything to the server.</p> <p><strong>SPECIAL NOTES:</strong><br> I also added an <code>else</code> as well as assigned <strong>uniqid();</strong> to <code>$uniqid</code> variable, so that both uploaded files will have the same number at the beginning.</p> <p>I added an echo'ed "Success" if files were successfully uploaded.</p> <p><strong>Here is working/tested code:</strong></p> <pre><code>&lt;form enctype="multipart/form-data" action="&lt;?php echo htmlentities($_SERVER['SCRIPT_NAME']) ?&gt;" method="post"&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="9000000"&gt; &lt;h3&gt;Thumbnail News Image: &lt;/h3&gt; &lt;input name="newsthumb" type="file" class='Input_file' /&gt; &lt;h3&gt;Full Image:&lt;/h3&gt; &lt;input name="newsmain" type="file" class='Input_file' /&gt; &lt;input type="submit" name="submit" value="send"&gt; &lt;/form&gt; &lt;?php error_reporting(E_ALL); ini_set('display_errors', '1'); if(isset($_POST['submit'])){ if (isset($_FILES['newsthumb']) &amp;&amp; isset($_FILES['newsmain'])) { // Commented out since it is not defined anywhere in your original posted code. // You will have to implement that in. // $allowedExts = array("jpg", "jpeg", "gif", "png"); $thumbimage = $_FILES['newsthumb']; $mainimage = $_FILES['newsmain']; $thumbname = strtolower($thumbimage['name']); $mainmane = strtolower($mainimage['name']); $thumbname = preg_replace("/[^A-Z0-9._-]/i", "_", $thumbname); $mainmane = preg_replace("/[^A-Z0-9._-]/i", "_", $mainmane); $uniqid = uniqid(); $thumbname = $uniqid."_".$thumbname; $mainmane = $uniqid."_".$mainmane; if (($_FILES["newsthumb"]["size"] &gt; 350000) || ($_FILES["newsmain"]["size"] &gt; 350000)) { // You can also use "die", just not with "exit;". // die("SORRY"); echo "One or Both of the files are too large.&lt;br&gt;"; exit; } else{ $uploaddir = "images/newsimage/"; $thumbsuccess = move_uploaded_file($thumbimage["tmp_name"], $uploaddir.$thumbname); $mainsuccess = move_uploaded_file($mainimage["tmp_name"], $uploaddir.$mainmane); echo "Success!!!"; } } } // else ending bracket ?&gt; </code></pre>
 

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