1

I have the following script for part of a form which allows a file upload, full script is here: Issue with image upload php: undefined index. It works ok in that it stops the script if there is no file selected and uploads when the form is fully populated (for logged in users only)

What I am trying to do with no luck so far, however is confine the upload type to pdf and jpeg only.

Any suggestions welcome

    <?php         
    if (is_uploaded_file ($_FILES ['image']['tmp_name'])) {
    if (move_uploaded_file($_FILES ['image']['tmp_name'], 
    "uploads/{$_FILES['image']['name']}")) { // Move the file over.
    echo '<p>The file has been uploaded!</p>';
    } else { // Couldn't move the file over.
    echo '<p><font color="red"> The thumbnail image could not be uploaded.</font></p>';
    $i = FALSE;
    }
    $i = $_FILES['image']['name'];
    } else {
    $i = FALSE;
    }
    ?>      

2 Answers 2

2

You should read the manual $_FILE type It would be something like:

if ($_FILES['file']['type'] == 'image/jpeg')  && ($_FILES["file"]["type"] == "application/pdf")
Sign up to request clarification or add additional context in comments.

1 Comment

Do you know how to display the signature in PDF format using this? my iframe is now showing the PDF signature, it is saving it but not showing it.
0

This will do the trick for you...

    <?php
    if(isset($_FILES['image'])&&(!empty($_FILES['image']))){  
    if (($_FILES['image']['type']== "image/jpeg")||($_FILES['image']['type'] == "application/pdf")){
$filename =$_FILES['image']['name'];
    $copy = copy($_FILES['image']['tmp_name'], "uploads/".$filename);
    if($copy){
    echo '<p>The file has been uploaded!</p>';
    }else{
    echo 'File is not a jpeg or pdf';
    }
    }else{
    echo '<p><font color="red"> The thumbnail image could not be uploaded.</font></p>';
    }
    }else{
    echo 'no image is selected';
    } 
    ?>

5 Comments

This script managed to get the pdf and jpeg verified and uploaded the script to the right folder, but it renamed the file name to 1. Is there any way of preserving the file name?
Oh sorry i didn't notice that. I have edited the answer.. now its okay check it.
did you getting same result..??
Yes, everything uploaded ok but the filename was called 1
I have tested it now, it works perfect for me. place the code you use here i will check if there is any other problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.