2011-12-08 90 views
0

我一直在嘗試創建這段代碼一段時間,只是想知道如果有人可能會比我更好地閱讀代碼,可能會發現爲什麼圖像不會最終結束我的服務器上,因爲我似乎有腦凍在這個:(從AS3和PHP的Flash網站上傳圖片到服務器

var fileRef:FileReference = new FileReference(); 
fileRef.addEventListener(Event.SELECT, selectHandler); 
fileRef.addEventListener(Event.COMPLETE, completeHandler); 
try 
{ 
var success:Boolean = fileRef.browse(); 
} 
catch (error:Error) 
{ 
trace("Unable to browse for files."); 
} 
function selectHandler(event:Event):void 
{ 
var request:URLRequest = new URLRequest("http://localhost/upload.php") 
try 
{ 
fileRef.upload(request); 
} 
catch (error:Error) 
{ 
trace("Unable to upload file."); 
} 
} 
function completeHandler(event:Event):void 
{ 
trace("uploaded"); 
} 
customerService.createClients(SlagsData); 
} 

然後這裏是服務器上的PHP

<?php 
define('UPLOAD_DIR', 'c:/wamp/www/IMAGES/'); 
define('UPLOAD_DIR_default', 'c:/wamp/www/IMAGES/0/image01.jpg'); 
$hostname_thatexclients = "localhost"; 
$database_thatexclients = "myexclients"; 
$username_thatexclients = "root"; 
$password_thatexclients = ""; 
$thatexclients = mysql_connect($hostname_thatexclients, $username_thatexclients, $password_thatexclients) or trigger_error(mysql_error(),E_USER_ERROR); 
set_time_limit (240); 




if($_FILES['yourpic']['size'] > 1) 
{ 
if($_FILES['yourpic']['size'] < 5000000) 
$newname = "image01.jpg"; 
$id = 0; 
$query = ("SELECT * FROM clients WHERE ID = (SELECT MAX(ID) FROM clients)") or die(mysql_error()); 
mysql_select_db($database_thatexclients, $thatexclients); 
$Result2 = mysql_query($query, $thatexclients) or die(mysql_error()); 
While($row = mysql_fetch_array($Result2)) 
{ 
$id = $row["ID"]; 
$id = ($id + "1"); 
} 
mkdir(UPLOAD_DIR.$id, 0777, true) or die ("Could not make directory"); 
$idr = ($id.'/'); 
move_uploaded_file($_FILES['yourpic']['tmp_name'],UPLOAD_DIR.$idr .$newname);// this one works 
} 
else 
{ 
$id = 0; 
} 

?> 

任何幫助將是巨大的:)

+0

我沒有得到任何錯誤消息只是UPLOADED跟蹤消息。但是當我檢查服務器時,沒有圖片! :( – WhiteFinger

+0

好吧,所以我已經從PHP中移動if語句,它創建了文件夾,但圖片不在文件中:( – WhiteFinger

+0

好吧,看起來代碼是如何尷尬的一直工作,只是一直是一個狡猾。我正在使用的JPEG圖片,因爲它只與另一個:) – WhiteFinger

回答

1

玉以及多麼尷尬rassing似乎代碼工作時間一直只是一個狡猾的.jpeg圖片