This question already has an answer here:
I'm new to uploading files and my handler isn't working correctly. I'm guessing the temp file handling is to blame. Can someone see what I'm doing wrong below? my images folder, located in the same folder as the current file, does not receive the uploaded image.
function uploadImage() {
var_dump($_FILES);
echo <<<'EOD'
=====$_FILES=====
EOD;
/*
array (size=1)
'imageCoupon' =>
array (size=5)
'name' => string 'diet.jpg' (length=8)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string '/tmp/phpBlfzEy' (length=14)
'error' => int 0
'size' => int 53196
* /
$fileName = $_FILES['imageCoupon']['name'];
$fileContents = $_FILES['imageCoupon']['tmp_name'];
var_dump($fileContents); // '/tmp/phpfTgBev' (length=14)
echo <<<'EOD'
=====$fileContents=====
EOD;
var_dump($fileName); // 'diet.jpg' (length=8)
echo <<<'EOD'
=====$fileName=====
EOD;
$destination = __FILE__ . 'images/' . $fileName;
var_dump($destination); // '/var/www/html/wptest2/wp-content/plugins/frequentVisitorCoupons/frequentVisitorCoupons.phpimages/diet.jpg' (length=105)
echo <<<'EOD'
=====$destination=====
EOD;
// take the file named in the POST request and move it to './images'
move_uploaded_file($fileContents, $destination);
};
</div>