0
我面临一个问题。我不能使用Angular.js和PHP将文件保存到本地文件夹。我在下面解释我的代码。文件无法上传到使用PHP和angular.js文件夹
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Upload Image :</span>
<input type="file"
class="filestyle form-control"
data-size="lg"
name="uploadme"
id="bannerimage"
ngf-select
ng-model="file"
ngf-pattern="'image/*'"
accept="image/*"
ngf-max-size="20MB"
ngf-min-height="100"
ngf-resize="{width: 100, height: 100}"
custom-on-change="uploadFile"
required="required">
</div>
上面的代码说我的文件输入字段。下面给出了控制器代码。
var today = $filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss');
var newpath = today + "_" + $scope.file.name;
var arrFile = {'name': newpath, 'size': $scope.file.size, 'type': $scope.file.type};
var productdata = $.param({
'op': 'add',
'catagory_id': $scope.catagory_name.value,
'product_name': $scope.product_name,
'status': $scope.product_status,
'ucp': $scope.unit_cost_price,
'usp': $scope.unit_sale_price,
'quantity': $scope.quantity,
'specification': $scope.specification,
'discount': $scope.discount,
'image': newpath,
'file': arrFile
});
$http({
method: 'POST',
url: "php/productInfo.php",
data: productdata,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
}, function errorCallback(response) {
});
这里我也有其他表格数据与文件。
productInfo.php:
if ($_REQUEST["op"]=="add") {
$name = $_FILES['file']['name'];
$tmpName = $_FILES['file']['tmp_name'];
move_uploaded_file($tmpName,'upload/'.$name);
}
这里我只提到file.I也纷纷上传文件夹,我的项目中folder.But我无法保存文件里面的PHP文件上传部分该文件夹。请帮我解决这个问题。
打印您在productinfo.php文件productdata和更新的问题 –
@saurabhkamble:Itried打印'$ _FILES [ '文件'] [ '名']; '但它没有返回任何东西。当尝试'$ _POST ['file'] ['name'];'它返回了我发送的文件名。 – subhra