Ive been trying to create this code for some time now and just wondered if someone out there who may read code better than me may work out why the image doesnt end up on my server as i seem to have brain freeze on this 🙁
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);
}
And then here is the php on the server
<?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;
}
?>
Any help would be great 🙂
Ok well how embarrassing would seem the code was working all the time just must of been a dodgy .jpeg picture