Uploading a file using php

Hello everyone, I am uploading a file from php everything is fine, but move_uploded_file is not working every variable displayed record and all file permissions are set

function uploadfile($filename)
{



    $filetype=$filename["type"];
    $filename=$filename['name']; 
    $filetempname=$filename['tmp_name'];
    if($filetype=="application/msword")
    {
        move_uploaded_file($filetempname,"resume/".$filename);

    }

}

      

+2


a source to share


5 answers


The array $filename

turns into a string at this line:$filename=$filename['name'];

I'm wondering why you didn't get the error message.



Try another var name instead of $ filename as a function parameter and I'm pretty sure it will work!

+5


a source


First of all install error reporting, on top of the script put this:

ini_set('display_errors', true);
error_reporting(E_ALL);

      

Then make sure the file type is indeed application/msword

echo $filetype;

      



And make sure the path is correct:

echo "resume/".$filename;

      

Also make sure that:

  • The directory has write permissions.
  • You point the right way
  • Try your way like "./resume/".$filename

  • Try to prefix your path with $_SERVER['DOCUMENT_ROOT']

+1


a source


if($filetype=="application/msword")

      

This line won't work because it's almost guaranteed that the browser won't try to determine the type of the mime file. Take a manual if

and it should work.

You should still try to validate the file differently (and absolutely make sure it is not PHP, because that would be a huge security vulnerability).

0


a source


Try to set display_errors = on, then you will get error messages ;-) Or print some message in the else statement to see if the if condition does not match.

0


a source


the first item you should check when loading is $ filename [" error "]

0


a source







All Articles