Im trying to upload files using angularJs and PHP.
Im using angular-file-upload, https://github.com/danialfarid/angular-file-upload.
The problem seems to be in my PHP-code, because it want move the file to the target directory.
Here is my angular:
$scope.onFileSelect = function($files) { //Vi har valt en eller flea filer //$files är en array innehållande de valda filerna att ladda upp. Dess namn, storlek och typ
for(var i = 0; i < $files.length; i++)
{
var file = $files[i];
$scope.upload = $upload.upload({
url: 'lib/actions.php',
data: {myObj: $scope.myModelObj},
file: file
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).success(function(data, status, headers, config) {
console.log(data);
});
}
};
This works great. A POST is made to my PHP-file:
if(isset($_FILES['file']))
{
$target_dir = "books/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_file))
{
echo "YES";
}
else
{
echo "wrong";
}
}
This always prints "wrong". I can't understand why. Anyone who can help me?
var_dump(getcwd())
to see, what is your current directory, and is that has abooks
subdirectory – lolka_bolka Nov 21 '14 at 13:36/var/www/cryptlib/lib/books
or/var/www/cryptlib/books
? – lolka_bolka Nov 21 '14 at 13:38777
, but don't forget to set back to775
or755
. – lolka_bolka Nov 21 '14 at 13:41