Reputation: 13
Im trying to add file uploading to my app but for some reason the php script doesnt move the file. I'm using angularjs and the code works fine but in the script it doesn't move/upload the file as it's supposed. Below is the code I have
<?php
$name = $_FILES['filee']['name'];
$tmp_name = $_FILES['filee']['tmp_name'];
$loc = '/media/img/';
if(move_uploaded_file($_FILES['filee']['name'], $loc)){
echo $_FILES['filee']['tmp_name'].$loc.$name;
}
?>
I don't see whats wrong with the script!!
Upvotes: 0
Views: 39
Reputation: 4321
you need to use tmp_name in the first argument of move_uploaded_file() function as below
<?php
$name = $_FILES['filee']['name'];
$tmp_name = $_FILES['filee']['tmp_name'];
$loc = 'media/img/'.$name; //desitination needs file name also
if(!is_dir('media/img/') && !file_exists('media/img') ) {
mkdir('media/img',0777,true);
}
if(move_uploaded_file($_FILES['filee']['tmp_name'], $loc)){
echo $_FILES['filee']['tmp_name'].$loc.$name;
}
?>
also make sure form has enctype attribute
Upvotes: 1