GRY
GRY

Reputation: 724

Uploading A file via a form

I have written a form which has 3 text inputs and one file input. This form posts to a PHP script, which saves the file, as well as performing some other business logic. The program worked well in my localhost, and even on my server.

The program is now embedded in a Facebook application, where it still works- but the uploaded files were not saving, initally; So I changed the uploads directory permissions to 777 (a broad stroke, I know). Now the uploaded files are being saved as a string of numbers "13474022561" with no extension.

Can anyone tell me why? Or how to fix this?

snippet of source code below:

  if($_FILES['resume']['type']!='')
  {
        $target_path = "resumes/";

        $target_path = $target_path .time().basename( $_FILES['resume']['name']!="");
        if($_FILES['resume']['type']=="application/vnd.openxmlformats-officedocument.wordprocessingml.document" || $_FILES['resume']['type']=="application/pdf")
        {
            if(move_uploaded_file($_FILES['resume']['tmp_name'], $target_path)) 
            {
                echo "success";
            }
            else
                echo "failure";
        }
        else 
        {
                echo "<center>Resume must be MS DOC or PDF <br/>";                    
                exit;
        }
  }

Upvotes: 0

Views: 137

Answers (1)

uınbɐɥs
uınbɐɥs

Reputation: 7351

This line of code:

$target_path = $target_path .time().basename( $_FILES['resume']['name']!="");

Should be:

$target_path = $target_path . time() . basename( $_FILES['resume']['name']);

Your current code is evaluated like this:

$target_path = 'resumes/' . time() . basename(true);

Which is probably not what you want.

Upvotes: 2

Related Questions