クラスを使用して画像をアップロードし、それをメインムービーに表示するフラッシュ as3 のボタンがあります。
私には伝記があります:
- www.MYSITE.com/test/
- www.MYSITE.com/test/uploads/
- www.MYSITE.com/test/uploads/images/
www.MYSITE.com/test/uploads/image.php の image.php というファイル
<?PHP
$target_path = $_REQUEST[ 'path' ];
$target_path = $target_path . basename( $_FILES[ 'Filedata' ][ 'name' ] );
if ( move_uploaded_file( $_FILES[ 'Filedata' ][ 'tmp_name' ], $target_path ) )
{
echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
}
else
{
echo "There was an error uploading the file, please try again!";
}
?>
そのまま:
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.geom.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
import src.events.*;
import src.image.*;
import src.file.*;
import src.load.*;
import src.ui.*;
import com.senocular.display.transform.*
public class ImageUploader extends Sprite
{
private var m_basePath : String = 'http://www.MYSITE.com/test/'; // web server path
private var m_uploadPath : String = 'uploads/'; // folder on server where you will allow images to be uploaded it has folder permissions set to 777 );
private var m_outputPath : String = 'output/'; // folder on server where images should be created; folder permissions are set to 777 );
public function ImageUploader ()
{
// allow script access;
Security.allowDomain( 'http://www.MYSITE.com/test' );
Security.allowInsecureDomain( 'http://www.MYSITE.com/test' );
// determine whether the swf is being accessed from the web orlocal hard drive;
m_isLocal = false;
init();
}
// display items;
public var upload : UIButton; // upload button on .fla stage;
// output container;
private var m_output : Sprite = new Sprite(); // container for image;
private var m_mask : Sprite = new Sprite(); // mask for image container;
private var m_progress : Sprite = new Sprite(); // upload / download indicator;
private var m_effect : Scribble; // covers image with random effect;
// vars;
private var m_isLocal : Boolean; // determines if swf is on web server or local drive;
private var m_fileMgr : FileManager; // manages the opening & upload of local files;
private var m_imagePHP : String = 'image.php'; // file that will manage image upload on your server;
private var m_finalImage : String; // final name of file on creation;
private var m_imageQuality : Number = 90; // jpeg or png export quality;
private var m_capture : Sprite; // set this equal to the sprite or movie clip that you wish to capture ( set to stage for entire movie );
private var m_downloader : GraphicLoader; // handles image download ( after upload is complete );
private var m_imageExtension : String = '.jpg'; // jpeg image extension;
// returns upload php file path based on whether or not the swf is a local publish or hosted on a web server;
public function get uploadPath () : String
{
return m_basePath + m_imagePHP;
}
// returns image creation php file path based on whether or not the swf is a local publish or hosted on a web server;
public function get createPath () : String
{
return m_basePath + m_imagePHP;
}
//returns image creation php file path based on whether or not the swf is a local publish or hosted on a web server;
public function get downloadPath () : String
{
return m_basePath + m_uploadPath;
}
//returns image creation php file path based on whether or not the swf is a local publish or hosted on a web server;
public function get finalImagePath () : String
{
return m_basePath + m_outputPath + m_finalImage + m_imageExtension;
}
//returns container for image capture container;
public function get captureContainer () : Sprite
{
return m_capture;
}
//sets container for image capture container;
public function set captureContainer ( inContainer : Sprite ) : void
{
m_capture = inContainer;
}
// browse for image files on click of upload button;
private function onBrowse ( e : MouseEvent ) : void
{
m_fileMgr.browse();
}
//track image upload progress;
private function onUploadProgress ( e : CustomEvent ) : void
{
trace( 'image uploading : ' + e.params.percent );
m_progress.scaleX = e.params.percent;
}
//fires when image upload is complete;
private function onImageUploaded ( e : CustomEvent ) : void
{
var dPath : String = String( downloadPath + e.params.fileName );
trace( 'image ready for download at : ' + dPath );
m_downloader.loadURL( dPath );
}
//track image download progress;
private function onDownloadProgress ( e : CustomEvent ) : void
{
trace( 'image downloading : ' + e.params.percent );
m_progress.scaleX = 1 - e.params.percent;
}
//fires on image download is complete;
private function onImageDownloaded ( e : CustomEvent ) : void
{
trace( 'image downloaded' );
// get image from loader;
var clip : * = new Bitmap( e.params.loaded.bitmapData.clone() ) ;
// add the image to the stage;
MovieClip(parent).textAssets.text_front.txtMc.holder_clipart.x = 215;
MovieClip(parent).textAssets.text_front.txtMc.holder_clipart.clipart.clipart_inside.inside.addChild(clip);
if (MovieClip(parent).textAssets.text_front.txtMc.holder_clipart.clipart.clipart_inside.inside.numChildren > 0)
{
MovieClip(parent).textAssets.text_front.txtMc.holder_clipart.clipart.clipart_inside.inside.removeChildAt(0);
}
clip.smoothing = true;
}
//fires if there is an error during upload;
private function onUploadError ( e : CustomEvent ) : void
{
trace( 'upload error' );
}
//fires if there is an error during download;
private function onDownloadError ( e : ErrorEvent ) : void
{
trace( 'download error' );
}
//downloads image to swf;
private function onGetCapturedImage ( e : MouseEvent ) : void
{
m_fileMgr.download( finalImagePath, m_finalImage + m_imageExtension );
}
// set up file manager / button listeners;
private function init () : void
{
// add output container to stage at 0,0;
addChildAt( m_output, 0 );
// check to make sure stage is available ( which it wouldn't be if this class were instantiated from another class );
if ( stage != null )
{
// set up stage;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
// create image mask that matches the stage height & width;
with ( m_mask.graphics )
{
beginFill( 0x000000 );
drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
}
}
// create progress indicator;
with ( m_progress.graphics )
{
beginFill( 0x000000 );
drawRect( 0, 0, upload.width, 1 );
}
addChild( m_progress );
m_progress.x = upload.x;
m_progress.y = upload.y + upload.height + 2;
// set container to use as image capture area;
captureContainer = m_output;
// set capture container mask;
captureContainer.mask = m_mask;
// add effect to image;
m_effect = new Scribble();
captureContainer.addChild( m_effect );
// show upload / scribble buttons;
upload.show();
// set progress bar to zero scale;
m_progress.scaleX = 0;
// set up file manager;
m_fileMgr = new FileManager( uploadPath, m_uploadPath );
m_fileMgr.addEventListener( FileManager.ON_PROGRESS, onUploadProgress );
m_fileMgr.addEventListener( FileManager.ON_UPLOAD_ERROR, onUploadError );
m_fileMgr.addEventListener( FileManager.ON_IMAGE_UPLOADED, onImageUploaded );
// listen to buttons;
upload.addEventListener( MouseEvent.CLICK, onBrowse );
// set up loader;
m_downloader = new GraphicLoader();
m_downloader.addEventListener( GraphicLoader.ON_LOAD_PROGRESS, onDownloadProgress );
m_downloader.addEventListener( GraphicLoader.ON_LOAD_COMPLETE, onImageDownloaded );
m_downloader.addEventListener( ErrorEvent.ERROR, onDownloadError );
}
//returns new string representing the month, day, hour, minute and millisecond of creation for use as the image name;
private function getUniqueName () : String
{
var d : Date = new Date();
return d.getMonth() + 1 + '' + d.getDate() + '' + d.getHours() + '' + d.getMinutes() + '' + d.getMilliseconds();
}
}
}
したがって、ムービーをアップロードしようとするたびに、フラッシュの出力に次のように表示されます。
image uploading : 1
ERROR: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038: I/O FILE ERROR. URL: http://www.MYSITE.com/test/image.php?path=uploads/"]
そのため、エラーがどこにあるのかわかりません。関連するすべてのファイルのアクセス許可を 777 に設定しました...