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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:40:33+00:00 2026-06-14T03:40:33+00:00

So I have a script which allows to files to get uploaded at once:

  • 0

So I have a script which allows to files to get uploaded at once:

<input style = "width: 90px;" name="book-image" type="file" id="image" value = "Upload">
<input style = "width: 90px;" name="book-preview" type="file" id="book" value = "Upload">

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.

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() && $pdf = uploadPreviewPdf()) {
                $newValues['imagefilename'] = $image;
                $newValues['previewfile'] = $pdf;
                if($qc->insertBook($newValues)) {
                    $message = "Added Book!";
                } else{
                    $error .= "Couldn't add book";
                }
            }
        }
} 

$qc->insertBook($values); adds the values to the database.

Here are the uploader functions:

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"))
&& ($_FILES["book-image"]["size"] < 2000000)
&& 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'))
         && ($_FILES['book-preview']['size'] < 6000000)
         && 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;
}
}

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

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

I have no idea why. Please help.

  • 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-14T03:40:34+00:00Added an answer on June 14, 2026 at 3:40 am

    I figured it out:

    It was the:

    if($image = uploadBookImage() && $pdf = uploadPreviewPdf()) {
         $newValues['imagefilename'] = $image;
         $newValues['previewfile'] = $pdf;
    }
    

    It needed to be

    if($image = uploadBookImage()) {
        $newValues['imagefilename'] = $image;
        if($pdf = uploadPreviewPdf()){         
             $newValues['previewfile'] = $pdf;
        }
    }
    

    Not sure why though. Can anyone explain why? My only guess would be that it doesn’t have time to complete both checks so quickly?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a script which allows me to output the list of files
I have a Perl script which will allow for a file to be uploaded
I have script which allows to display Bing search results. I can call for
I have a script which allows to display favicon based on the url over
I have a script which allows to display favicons based on the url: Example
I have a script which allows to display search results on keyup: JsFiddle I
I have a script which allows to display search results. Given a query there
I have a script which allows to execute Bash processes in the background, i
I wrote a PHP script that allows me to get the dimensions (width and
I am working on a PHP upload script which allows uploading only PDF files.

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.