使用AngularJS和PHP将图像上载到服务器路径
正如前面提到的问题,我有一个关于如何将图像上传到服务器的问题。我在网上搜索了一下,找到了一些参考资料,但我仍然不明白它们是如何工作的。例如: 图像是如何上传的?因为那里没有提交按钮。我已经按照那里的代码进行了尝试,仍然无法上传文件 我还尝试从这里查看一些可用的模块: 找了几个小时后,我仍然不知道如何使用它们。是否有更简单或更容易理解的指南供我遵循?提前谢谢 编辑:如果有更简单的示例,如只上载一个文件,请将我链接到它,因为有许多示例非常先进,包括许多部分,如上载多个文件等。请尝试使用html使用AngularJS和PHP将图像上载到服务器路径,php,angularjs,image,upload,Php,Angularjs,Image,Upload,正如前面提到的问题,我有一个关于如何将图像上传到服务器的问题。我在网上搜索了一下,找到了一些参考资料,但我仍然不明白它们是如何工作的。例如: 图像是如何上传的?因为那里没有提交按钮。我已经按照那里的代码进行了尝试,仍然无法上传文件 我还尝试从这里查看一些可用的模块: 找了几个小时后,我仍然不知道如何使用它们。是否有更简单或更容易理解的指南供我遵循?提前谢谢 编辑:如果有更简单的示例,如只上载一个文件,请将我链接到它,因为有许多示例非常先进,包括许多部分,如上载多个文件等。请尝试使用html &l
<div type="file" ngf-drop ng-model="files" class="container drop-box text-center"
ngf-drag-over-class="dragover" ngf-multiple="true" ngf-allow-dir="true"
ngf-accept="'.jpg,.png'"><input type="hidden" name="image_id" >Drop Images here</div>
将图像放到这里
试试你的控制器
controller: function($scope,$http,$timeout,Upload) {
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: 'php/upload.php',
headers: {'Content-Type': file.type},
method: 'POST',
data: file,
file: file,
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
$scope.image_submit = function() {
$http.post('php/slider.php?action=add_image',
{
'img_name' : config.file.name,
'img_src' : '../images/' + config.file.name
}
)
.success(function (data, status, headers, config) {
$scope.get_image();
})
.error(function(data, status, headers, config){
});
};
$scope.image_submit();
});
}
}
};
控制器:函数($scope,$http,$timeout,Upload){
$scope.$watch('files',function(){
$scope.upload($scope.files);
});
$scope.upload=函数(文件){
if(files&&files.length){
对于(var i=0;i
这在你的php文件中
<?php
$filename = $_FILES['file']['name'];
$destination = '../images/' . $filename;
move_uploaded_file( $_FILES['file']['tmp_name'] , $destination );
?>
您还需要创建一个db连接并创建两个php函数,一个用于从数据库中获取图像,一个用于创建图像,另一个用于在控制器中获取图像。添加图像的函数我已经在控制器中提供给您了。为什么要在使用php i将文件上载到服务器时使用angular js这很简单,也很简单?我正在考虑使用angularjs调用php进行上传过程。这是上传图像文件的一种可行方式吗?因为我正在尝试提交一个表单,表单中包含图像文件的数据,这些数据将存储在折叠的at数据库中。我以前已经尝试过使用它。不太了解示例源代码。它似乎是not也使用任何php脚本。你能解释一下关于
上传的问题吗?因为我得到了未知的提供者:上传提供者