Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with uploading multiple files PHP
    text
    copied!<p>On my site I have a page where users can upload files to go with the news post they're adding. I allow them to upload one image and one sound file. They don't have to add files if they don't want to, or they can just add one if they want. Problem I'm having is that my script only works if the user selects both files. If they choose none, or only one, then the script spits out 'Invalid File' as it can't find a file where one hasn't been selected.</p> <p>I tried using: </p> <pre><code>if (isset($_FILES['filetoupload1'])) { if (($_FILES["filetoupload1"]["type"] == "image/gif") || ($_FILES["filetoupload1"]["type"] == "image/jpeg") || ($_FILES["filetoupload1"]["type"] == "image/pjpeg") || ($_FILES["filetoupload1"]["type"] == "image/png") || ($_FILES["filetoupload1"]["type"] == "image/jpg") ) { if ($_FILES["filetoupload1"]["error"] &gt; 0) { echo "Return Code: " . $_FILES["filetoupload1"]["error"] . "&lt;br /&gt;"; } else { if (file_exists("media/" . $_FILES["filetoupload1"]["name"])) { echo $_FILES["filetoupload1"]["name"] . " already exists. "; } move_uploaded_file( $_FILES["filetoupload1"]["tmp_name"], "media/" . $_FILES["filetoupload1"]["name"] ); } } else { echo "Invalid file"; } } if (isset($_FILES['filetoupload2'])) { if ($_FILES["filetoupload2"]["type"] == "audio/mp3") { if ($_FILES["filetoupload2"]["error"] &gt; 0) { echo "Return Code: " . $_FILES["filetoupload2"]["error"] . "&lt;br /&gt;"; } else { if (file_exists("media/" . $_FILES["filetoupload2"]["name"])) { echo $_FILES["filetoupload2"]["name"] . " already exists. "; } move_uploaded_file( $_FILES["filetoupload2"]["tmp_name"], "media/" . $_FILES["filetoupload2"]["name"] ); } } else { echo "Invalid file"; } } </code></pre> <p>and then </p> <p><code>if((isset($_FILES['filetoupload1'])) &amp;&amp; (isset($_FILES['filetoupload2']))) { }</code> </p> <p>before both first and second upload scripts if the user had selected both image and audio file. In other words it did this:</p> <pre><code>if filetoupload1 isset then run upload script that filters images. if filetoupload2 isset then run upload script that filters audio. if filetoupload1 AND filetoupload2 isset then run both upload scripts. </code></pre> <p>I have it set like that. The above should allow for all combinations of file uploads. right? but it doesnt work so.. </p> <p>Now I have no idea what to do. Here's the upload script for the audio, the image one is pretty much the same:</p> <p>Can someone tell me what I'm doing wrong please!</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