Wino
03-08-2008, 01:03 AM
I've got two domains, and I'm going to be using one to upload, store, and serve data to the other.
I've written the Flash Code to get the browse file, and I've searched the help files, here, and flash-db site to do the rest. I guess I'm just php-ignorant. Anyway, here's the basic flash code, almost directly from the Flash help files:
var fileLoc:FileReference = new FileReference();
var imageTypes:FileFilter = new FileFilter
("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
var vidTypes:FileFilter = new FileFilter("Video Files (*.flv)","*.flv");
var allTypes:Array = new Array(imageTypes, textTypes, vidTypes);
fileLoc.addEventListener(Event.SELECT, selectHandler);
fileLoc.addEventListener(Event.COMPLETE, completeHandler);
try {
var success:Boolean = fileLoc.browse(allTypes);
}
catch (error:Error) {
trace("Unable to browse for files.");
}
function selectHandler(event:Event):void {
var myRequest:URLRequest =
new URLRequest("http://[domain]/fileUpload.php")
try {
fileLoc.upload(myRequest);
}
catch (error:Error) {
trace("Unable to upload file.");
}
}
function completeHandler(event:Event):void {
trace("uploaded");
}
That all works, I think (It appears to, until I select the file, anyway). I'm trying to write the fileUpload.php file now, and have found the following code, from one of the three areas I mentioned above (who knows which one?)
<?php
$MAXIMUM_FILESIZE = 1024 * 5000; // 5MB
$MAXIMUM_FILE_COUNT = 100; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/".$_FILES['Filedata']['name']);
$type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
if ($type == 1 || $type == 2 || $type == 3)
{
rename("./temporary/".$_FILES['Filedata']['name'], "./images/".$_FILES['Filedata']['name']);
}
else
{
unlink("./temporary/".$_FILES['Filedata']['name']);
}
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory)) {
array_push($files, array('./images/'.$file, filectime('./images/'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) - $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b) {
if ($a[1] == $b[1]){
return 0;
}
else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>
The problem is that I'm not sure how to continue. Do I upload the php file to my storage server? I'm not worried about security or sandbox or access issues, just how to proceed.
Do I have to rename some variables? How does the PHP file know what's coming, and how do they correspond? Is fileData really fileLoc from my AS file?
I will have complete access to the folders, so all directories will exist. I know some of the PHP can be eliminated, but I'm afraid to touch it.
Any and all help is appreciated. I'm not stupid. All I normally need is a cursory explanation, and a point in the right direction.
I've written the Flash Code to get the browse file, and I've searched the help files, here, and flash-db site to do the rest. I guess I'm just php-ignorant. Anyway, here's the basic flash code, almost directly from the Flash help files:
var fileLoc:FileReference = new FileReference();
var imageTypes:FileFilter = new FileFilter
("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");
var vidTypes:FileFilter = new FileFilter("Video Files (*.flv)","*.flv");
var allTypes:Array = new Array(imageTypes, textTypes, vidTypes);
fileLoc.addEventListener(Event.SELECT, selectHandler);
fileLoc.addEventListener(Event.COMPLETE, completeHandler);
try {
var success:Boolean = fileLoc.browse(allTypes);
}
catch (error:Error) {
trace("Unable to browse for files.");
}
function selectHandler(event:Event):void {
var myRequest:URLRequest =
new URLRequest("http://[domain]/fileUpload.php")
try {
fileLoc.upload(myRequest);
}
catch (error:Error) {
trace("Unable to upload file.");
}
}
function completeHandler(event:Event):void {
trace("uploaded");
}
That all works, I think (It appears to, until I select the file, anyway). I'm trying to write the fileUpload.php file now, and have found the following code, from one of the three areas I mentioned above (who knows which one?)
<?php
$MAXIMUM_FILESIZE = 1024 * 5000; // 5MB
$MAXIMUM_FILE_COUNT = 100; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/".$_FILES['Filedata']['name']);
$type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
if ($type == 1 || $type == 2 || $type == 3)
{
rename("./temporary/".$_FILES['Filedata']['name'], "./images/".$_FILES['Filedata']['name']);
}
else
{
unlink("./temporary/".$_FILES['Filedata']['name']);
}
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory)) {
array_push($files, array('./images/'.$file, filectime('./images/'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) - $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b) {
if ($a[1] == $b[1]){
return 0;
}
else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>
The problem is that I'm not sure how to continue. Do I upload the php file to my storage server? I'm not worried about security or sandbox or access issues, just how to proceed.
Do I have to rename some variables? How does the PHP file know what's coming, and how do they correspond? Is fileData really fileLoc from my AS file?
I will have complete access to the folders, so all directories will exist. I know some of the PHP can be eliminated, but I'm afraid to touch it.
Any and all help is appreciated. I'm not stupid. All I normally need is a cursory explanation, and a point in the right direction.