AngularJS에서 이미지 업로드에 문제가 있습니다. 내가 https://github.com/danialfarid/angular-file-uploadAngularJS 이미지 업로드 PHP를 사용하여
내 문제는 내가 업로드하려고 내 이미지 내 PHP 파일로 전송되지 않는 것입니다 사용하려고 다른 문제로 Angularjs - File upload with php
: 여기에이 질문을 발견했다.
다음은 내가 사용하는 코드입니다.
PlayerController.js
angular.module('lax').controller('PlayerController', function($scope, $http, $upload) {
$scope.onFileSelect = function($files) {
$scope.message = "";
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
console.log(file);
$scope.upload = $upload.upload({
url: 'php/upload.php',
method: 'POST',
file: file
}).success(function(data, status, headers, config) {
$scope.message = data;
}).error(function(data, status) {
$scope.message = data;
});
}
};
});
HTML
<div ng-show="newplayer.functie == 'update'">
<h3>Profile Pic</h3>
<div>
<input type="file" name="image" id="image" ng-file-select="onFileSelect($files)">
<br/>
<span class="errorMsg">{{ message}}</span>
</div>
</div>
그래서 upload.php로
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
$extensions = array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
$errors[]="image extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size cannot exceed 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"../../Img/PlayerAvatar/".$file_name);
echo $fname . " uploaded file: " . "images/" . $file_name;
}else{
print_r($errors);
}
}
else{
$errors= array();
$errors[]="No image found";
print_r($errors);
}
?>
(가) "경우가 (는 isset가 ($이 _ FILES는 [ '이미지']))"제공 그 결과 false. 나는 stackoverflow와 angularJS에 익숙하지 않아 어떤 멍청한 질문이라도 유감스럽게 생각한다.
안녕하세요, 당신은 서버에 muliple 이미지를 업로드 나에게 각 2/4에 대한 예/링크를 제공 할 수 있습니다 문제는 이미지 파일 그것은 했어야 했어야 $ _FILES [ '이미지']와 함께했다 . –