Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with uploading multiple uploaded files
    primarykey
    data
    text
    <p>So I have a script which allows to files to get uploaded at once: </p> <pre><code>&lt;input style = "width: 90px;" name="book-image" type="file" id="image" value = "Upload"&gt; &lt;input style = "width: 90px;" name="book-preview" type="file" id="book" value = "Upload"&gt; </code></pre> <p>Here is the receiving script: if the image exists, it tests if the preview (pdf) exists and then runs 2 functions to upload each image and pdf.</p> <pre><code>if(file_exists($_FILES['book-image']['tmp_name']) || is_uploaded_file($_FILES['book-image']['tmp_name'])) { //If there is a preview or non-free book if((file_exists($_FILES['book-preview']['tmp_name']) || is_uploaded_file($_FILES['book-preview']['tmp_name']))) { //valid - upload image, preview and add book if($image = uploadBookImage() &amp;&amp; $pdf = uploadPreviewPdf()) { $newValues['imagefilename'] = $image; $newValues['previewfile'] = $pdf; if($qc-&gt;insertBook($newValues)) { $message = "Added Book!"; } else{ $error .= "Couldn't add book"; } } } } </code></pre> <p>$qc->insertBook($values); adds the values to the database. </p> <p>Here are the uploader functions: </p> <pre><code>function uploadBookImage() { $allowedExts = array("jpg", "jpeg", "gif", "png"); $gay = explode(".", $_FILES['book-image']['name']); $extension = end($gay); $target_path = "../images/books/"; $filename = $_FILES["book-image"]["name"]; $target_path = $target_path . basename($_FILES['book-image']['name']); if ((($_FILES["book-image"]["type"] == "image/gif") || ($_FILES["book-image"]["type"] == "image/jpeg") || ($_FILES["book-image"]["type"] == "image/png") || ($_FILES["book-image"]["type"] == "image/pjpeg")) &amp;&amp; ($_FILES["book-image"]["size"] &lt; 2000000) &amp;&amp; in_array($extension, $allowedExts)){ if (file_exists($target_path)) { return false; } else { if(move_uploaded_file($_FILES['book-image']['tmp_name'], $target_path)) { echo $filename; return $filename; } } } else { return false; } }//function function uploadPreviewPdf() { $allowedExts = array("pdf"); $gay = explode(".", $_FILES['book-preview']['name']); $extension = end($gay); $target_path = '../previews/'; $filename = $_FILES['book-preview']['name']; $target_path = $target_path . basename($_FILES['book-preview']['name']); if((($_FILES['book-preview']['type'] == 'application/pdf')) &amp;&amp; ($_FILES['book-preview']['size'] &lt; 6000000) &amp;&amp; in_array($extension, $allowedExts)) { if(file_exists($target_path)) { return false; } else { if(move_uploaded_file($_FILES['book-preview']['tmp_name'], $target_path)) { return $filename; } } } else { return false; } } </code></pre> <p><strong>The Problem: When I upload both, It adds the value 1 for the image name, and the filename for the pdf - to the database. However if I upload only the image it add the image name into the database</strong></p> <p><strong>Output of var dump when uploading image: outputs image file name and Output of var dump when uploading image and pdf: outputs image file name</strong></p> <p>I have no idea why. Please help. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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