[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

Problems uploading files through flex

I'm having problems upload files through my flex app online, it works offline fine on my windows test server but not on my online virtual hosting running via apache.

In my code snipplet I have attached the code I use in flex to transfr the file. My PHP code on the other end works, I've tested that but for some reason my app gets stuck.

the variables used are as follows

serverSideScript = http://instrumenttrack.com/flashservices/services/upload.php


public function uploadFile():void {
				
			if(serverSideScript == "null") {
				Alert.show("Please enter a record to attach file");
			} else {
				//Alert.show(serverSideScript);
				try {
					//Alert.show(serverSideScript);
					//urlRequest = new URLRequest(serverSideScript);
					fileReferenceList = new FileReferenceList();
					fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);
					fileReferenceList.browse();
				}
					catch (error:Error) {
				    trace("Unable to upload file.");
					}	
				}
			}
			
			public function fileSelectedHandler(event:Event):void {
				var fileReference:FileReference;
				var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
				var fileList:Array = fileReferenceList.fileList;
 
				// get the first file that the user chose
				fileReference = FileReference(fileList[0]);
				
				urlRequest = new URLRequest(serverSideScript);
									
				// upload the file to the server side script
				fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
				fileReference.upload(urlRequest);
				
				// update the status text
				statusText.text = "Uploading...";
			}
			
			public function uploadCompleteHandler(event:Event):void {
				statusText.text = "";
				Alert.show("File Uploaded: " + event.target.name);
				GetListDowloads();
			}

Open in new window

0
Vype
Asked:
Vype
  • 3
  • 3
  • 2
  • +3
6 Solutions
 
dr_dedoCommented:
most of times, it is folder permission problem, CHMOD your upload folder to "777" by using your ftp software
0
 
VypeAuthor Commented:
It's not actually getting to my PHP side of the script, its halting before the stage where the PHP sript in run, I've tested this.
0
 
julianopolitoCommented:
If it is working locally in your local webserver, maybe it is some configuration directive, like upload_max_filesize or post_max_size. Have you checked those directives in your online server?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
evcrCommented:

show us the php script
0
 
Gary BenadeCommented:
try this and post any error messages you get
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
					
			private var serverSideScript:String = "http://localhost:9010/php/uploadlogo.php";
			private var fileReference:FileReference;
			
			public function uploadFile():void 
			{				
				if(serverSideScript == "null") 
				{
					Alert.show("Please enter a record to attach file");
				} 
				else 
				{
					fileReference = new FileReference();
					fileReference.addEventListener(Event.SELECT, selectEvent);
		            fileReference.addEventListener(ProgressEvent.PROGRESS, progressEvent);						
					fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
			        fileReference.addEventListener(IOErrorEvent.IO_ERROR, ioErrorEvent);							            
					fileReference.browse();
				}
			}
			private function selectEvent(event:Event):void
			{
				filename.text = fileReference.name;
				progressBar.setProgress(0, 100);
				progressBar.label = "Loading 0%";	
				var urlRequest:URLRequest = new URLRequest(serverSideScript);									
				urlRequest.method = URLRequestMethod.GET;
				fileReference.upload(urlRequest);				
				statusText.text = "Uploading...";						
			}			
			private function ioErrorEvent(event:IOErrorEvent):void
			{
				Alert.show("IOError:" + event.text);
			}		
			private function progressEvent(event:ProgressEvent):void 
			{
				progressBar.setProgress(event.bytesLoaded, event.bytesTotal);
			}										
			public function uploadCompleteHandler(event:Event):void 
			{
				statusText.text = "Upload OK";
				Alert.show("File Uploaded: " + event.target.name);
			}			
		]]>
	</mx:Script>	
	<mx:Button x="57" y="80" label="Button" click="uploadFile()"/>
	<mx:Label id="statusText" x="57" y="110" text="Label"/>
	<mx:Label id="filename" x="57" y="136" text="Label"/>
	<mx:ProgressBar id="progressBar" mode="manual"  x="57" y="162"/>
</mx:Application>

Open in new window

0
 
Gary BenadeCommented:
of course, first change line 7 to
private var serverSideScript:String = "http://instrumenttrack.com/flashservices/services/upload.php";
0
 
evcrCommented:
I/O error 2038

please post the php script

0
 
Robinsonx6Commented:
Worth noting here that php will often badly handle large files, what size are you trying to upload and is the flex app on the same server and same domain
0
 
Robinsonx6Commented:
just write this two lines in the .htaccess file at the root folder

SECFILTERENGINE OFF
SECFILTERSCANPOST OFF




this cured it for us
0
 
Robinsonx6Commented:
You have to make sure you have read/write privileges on the the folder you are trying to complete the upload to.

Also consider the php.ini file
You may have to change the php.ini:

upload_max_filesize = 1024M (set this to the maximum file size you wish to handle in your php)
post_max_size = 1024M (or more, equivalent to the upload_max_filesize)

Also short_open_tag = on (this must be set in the php.ini, or you get errors.)
0
 
evcrCommented:
do you still need help with this? I have a stable app running gigs of file transfers so it is possible with Flex, although I remember it was somewhat tricky to set up.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now