我打算將文件從閃存上傳到服務器。當用戶開始輸入自己的用戶名,然後我把它發送到PHP的,這樣說:從閃存上傳文件到服務器PHP
var myusername:String = username.text;
username.restrict = "A-Za-z0-9";
login_btn.addEventListener(MouseEvent.CLICK,login);
function login (evt:MouseEvent):void{
var loader : URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://domain/uploads/upload.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
var userid:String = myusername;
variables.ID = userid;
request.data = variables;
loader.load(request);
}
upload.php的:
<?php
$myuser = $_POST['ID'];
$uploads_dir = './uploads/'.$myuser;
if($_FILES['Filedata']['error'] == 0){
if(move_uploaded_file($_FILES['Filedata']['tmp_name'],
$uploads_dir.$_FILES['Filedata']['name'])){
exit();
}
}
echo 'error';
exit();
?>
的問題是,文件上傳到上傳文件夾不在用戶文件夾中。任何人都可以幫助我嗎?
檢查'$ _POST ['ID']'實際上是否包含一個值,否則'$ uploads_dir'就是上傳目錄 –
嘗試var_dump($ myuser); – Hackerman