如何跟踪上传是否成功并使用角度和ng文件上传重定向到某个页面(https://github.com/danialfarid/ng-file-upload)
目前它上传文件,但如果表单无法插入mysql或显示成功页面,我需要显示错误
以下是我的角度函数
Upload.upload({
url: 'api/upload-image.php',
method: 'POST',
file: file,
data: {
'awesomeThings': $scope.awesomeThings,
'targetPath' : '/media/'
}
})
在我的PHP代码中
$status = $this->Upload_tools->add($data);
如果上传是访问状态,则会返回true
或false
如果success
我想要显示此页面
$location.path('/show/'+qid);
答案 0 :(得分:0)
请参阅ng-file-upload read.me中的示例代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <limits.h>
#define SIZE 1000
int arrSum(int arr[SIZE], int b)
{
if(b < 0)
{
return 0;
}
else
{
return arr[b] + arrSum(arr, b-1);
}
}
int main()
{
int inputNum = 0;
int arr1[SIZE];
memset(&arr1, 0, sizeof(arr1));
int sum = 0;
int avg = 0;
int min = INT_MAX;
int max = INT_MIN;
int location1 = 0,location2 = 0;
srand(time(NULL));
printf("Enter an integer between 0 and 1000: ");
scanf("%d",&inputNum);
for(size_t q = 0; q < inputNum; ++q)
{
arr1[q] = rand() % 1001;
}
for(size_t j = 0; j < inputNum; ++j)
{
if(arr1[j] > max)
{
max = arr1[j];
location1 = j;
}
if (arr1[j] < min)
{
min = arr1[j];
location2 = j;
}
}
printf("min: %6d pos:%4d\n",min,location2);
printf("max: %6d pos:%4d\n",max,location1);
sum = arrSum(arr1, inputNum);
printf("sum: %6d\n", sum );
avg = sum / inputNum;
printf("avg: %6d\n\n",avg);
printf(" Pos | Val\n");
printf("-------------\n");
for (size_t i = 0; i < inputNum; ++i)
{
printf("%zu |%d\n", i,arr1[i]);
}
return 0;
}
现在,您的代码将是这样的:
$scope.upload = function (file) {
Upload.upload({
url: 'upload/url',
data: {file: file, 'username': $scope.username}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});