我正面临一个问题。我试图使用Angular.js和PHP上传文件,但我可以成功发送文件参数值,但在PHP方面,我无法得到它。我在下面解释我的代码。
workspesh.html:
<div class="pad-bot-10">
<label for="attachment">Attachment</label>
<div class="form-group" style="margin-bottom:0px;">
<input type="file" name="documentlink" id="documentlink" ng-model= "subdata.form.documentlink" onchange="angular.element(this).scope().uploadedHosFile(this)" class="file">
<div class="input-group col-xs-12">
<input type="text" class="form-control" placeholder="Attachment" id="documenturl">
<span class="input-group-btn">
<button class="browse btn btn-primary" type="button">Attachment</button>
</span> </div>
</div>
</div>
workspeshController.js:
$scope.uploadedHosFile = function(element) {
var files = element.files;
var filename=files[0]['name'];
var filetype=filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
var size=files[0].size;
if ($.inArray(filetype, ["php", "exe"] ) != -1) {
alert("Please upload document or image only !!");
return false;
}else if (size > 10485760) {
alert("File size shouldn't be more than 10MB !!!");
return false;
}else{
var allHosImg=filename;
$scope.hosfiles = element.files;
document.getElementById('documenturl').value = allHosImg;
}
};
$http({
method : 'POST',
url : 'php/myworkspesh.php?action=saveAddEvent',
processData: false,
headers: {'Content-Type': undefined},
transformRequest:function(){
var formData = new FormData();
formData.append("documenturl", $scope.hosfiles);
return formData;
},
data : $scope.form,
}).success(function(data){
console.log(data);
})
myworkspesh.php:
class Myworkspesh{
public function saveAddEvent($postData){
$url = "myworkspaceapi.php?action=saveAddEvent";
$numfile = 0;
print_r($_FILES);exit;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);
curl_close ($ch);
echo $response;
}
}
$obj = new Myworkspesh();
$action = (isset($_GET['action']))?$_GET['action']:'';
if(method_exists($obj,$action)){
$obj->$action($_POST);
}else{
return false;
}
myworkspaceapi.php:
$action = (isset($_GET['action']))?$_GET['action']:'';
class MyworkspaceApi{
public function saveAddEvent(){
$documenturl = ($_REQUEST['documenturl'] != 'undefined')?$_REQUEST['documenturl'] : '';
echo json_encode($documenturl);
}
}
$obj = new MyworkspaceApi();
$action = (isset($_GET['action']))?$_GET['action']:'';
if(method_exists($obj,$action)){
$obj->$action($dbobj);
}else{
return false;
}
这里在PHP边脚本中我无法获得任何文件值。在这里,我需要获取总文件值,并将其上传到本地文件夹。
答案 0 :(得分:0)
检查&#34; post_max_size&#34;的值和&#34; max_file_uploads&#34;在php.ini中。如果上传的文件大小超过这两个配置,您将不会在服务器端收到任何内容。