Ucoz не позволяет использовать PHP файлы. Потребовалось флэшку, которая успешно работает на обычном хостинге разместить на юкозе. Флэшка позволяет юзеру загружать со своего компа изображения на сервер в папку "uploads2" при этом используется php-файл upload2.php такого содержания:
PHP код:
<?php
if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$uploadDirectory = "uploads2/";
$uploadFile = $uploadDirectory . basename($_FILES['Filedata']['name']);
copy($_FILES['Filedata']['tmp_name'], $uploadFile);
}
?>
Естественно что файл и папка лежат на стороннем хостинге.
Теперь AS2 код для загрузки изображения:
Код AS1/AS2:
//import the FileReference Object
import flash.net.FileReference;
//initial settings - since no upload file type selet yet user cannot upload a file
uploadButn.enabled = false;
browseButn.enabled = false
//create a new FileReference object
var fileRef:FileReference = new FileReference();
//create a listener object for FileReference events
var fileRefListener:Object = new Object();
//create a listener object for comboBox events
var myComBoxListener:Object = new Object();
var isDefault:Boolean = false;
_root.bigfoto._visible=false
//===================== COMBO BOX EVENT HANDLER =====================//
fileDescription = "Images";
fileExtension = "*.jpg; *.jpeg; *.gif; *.png";
reDrawPB ("progressBar", 215.9, 128);
browseButn.enabled = true;
//apply object listener to the file reference object
fileType.addEventListener("change", myComBoxListener);
//===================== FILEREFERENCE EVENT HANDLER =====================//
//When user selects a file from the file-browsing dialog box,
//the onSelect() method is called, and passed a reference to the FileReference object
fileRefListener.onSelect = function (fileRef:FileReference):Void {
uploadButn.enabled = true;
reDrawPB("progressBar", 215.9, 128);
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File is selected to upload \n";
status_txt.vPosition = status_txt.maxVPosition;
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "-------------------------------FILE DETAILS------------------------------- \n";
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Size: " + fileRef.size + " bytes" + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Type: " + fileRef.type + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "File Name: " + fileRef.name + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "Date Created: " + fileRef.creationDate + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "Date Modified: " + fileRef.modificationDate + '\n';
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "--------------------------------------------------------------------------------- \n";
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Attempting to upload " + fileRef.name + '\n';
//upload the file to the PHP script on the server
//put your domain in the upload() method
if(fileRef.size<153600)
{
fileRef.upload("http://www.****.ru/upload2.php");
userpicd._visible=false
}else{
_root.bigfoto._visible=true
_root.bigfoto.gotoAndPlay(2)
}
}
//When user dismiss the file-browsing dialog box,
//the onCancel() method is called, and passed a reference to the FileReference object
fileRefListener.onCancel = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="User terminated file upload. \n";
}
//When the file upload/download process started,
//the onOpen() method is called, and passed a reference to the FileReference object
fileRefListener.onOpen = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Opening file " + fileRef.name + '\n';
}
//The onProgress() method is called periodically during the file upload operation
fileRefListener.onProgress = function (fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
}
//When the file upload/download operation is successfully complete,
//the onComplete() method is called, and passed a reference to the FileReference object
fileRefListener.onComplete = function (fileRef:FileReference):Void {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text += "The "+fileRef.name + " ha been uploaded.\n";
//upload is now complete, disable the upload & browse button
uploadButn.enabled = false;
downloadImage(fileRef.name);
}
//********************************* ERROR EVENT HANDLING *********************************//
//This method will be called if and only if an upload fails because of an HTTP error
fileRefListener.onHTTPError = function (fileRef:FileReference, error:Number) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="HTTP error: with " + fileRef.name + " :error #" + error + '\n';
}
//This method will be called if and only if a file input/output error occur
fileRefListener.onIOError = function (fileRef:FileReference) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="HTTP error: with " + fileRef.name + '\n';
}
//This method will be called if and only if an upload fails because of a security error
//9 out of 10 time this error occus is because of the user Flash8 player security settings
fileRefListener.onSecurityError = function (fileRef:FileReference, errorString:String) {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Security error: with " + fileRef.name + " : " + errorString + '\n';
}
//****************************************************************************************//
//attach Listener to the FileReference Object
fileRef.addListener(fileRefListener);
//button event for the browse button
browseButn.clickHandler = function () {
//The browse function is the key, coz it displays a file-browsing dialog box
//in which the user can select a local file to upload
fileRef.browse([{description: fileDescription, extension: fileExtension}]);
}
/*uploadBtn.onMouseDown = function()
{
fileRef.browse([{description: fileDescription, extension: fileExtension}]);
}*/
//Button event for the upload button
uploadButn.clickHandler = function () {
status_txt.vPosition = status_txt.maxVPosition;
status_txt.text +="Attempting to upload " + fileRef.name + '\n';
fileRef.upload("http://www.****.ru/upload2.php");
}
crossdomain.xml настроил все прописал.
вроде загрузка в окне флэшки происходит, вот что пишет:
Цитата:
-------------------------------FILE DETAILS-------------------------------
File Size: 8559 bytes
File Type: .png
File Name: sssss.png
Date Created: Sun Dec 27 00:42:43 GMT+0300 2009
Date Modified: Mon Nov 30 17:33:54 GMT+0300 2009
---------------------------------------------------------------------------------
Attempting to upload sssss.png
Opening file sssss.png
The sssss.png ha been uploaded.
|
Но физически загрузка файла не осуществляется.
Помогите, плиз, что можно сделать в этом запутанном случае?
Добавлено через 4 часа 14 минут
В общем с этим сам разобрался. Загружает изображения на сервер нормально.
Но теперь их нужно вывести в флэш. У меня работает такой скрипт на родном сервере:
Код AS1/AS2:
// show uploaded image in scrollPanel
function downloadImage(file:Object):Void {
flg="http://www.****.ru/uploads2/" + file
_root.ojj.NEO(flg);
_root.my_foto=1
}
А через Юкоз не хочет работать.
Что посоветуете?