Error with Flash and PHP Uploader

Status
Not open for further replies.

halobob

Solid State Member
Messages
8
I am trying to create a website for an animation business I'm starting. The website is private access for employees used for development. I needed to allow the employees to upload files to the website and being that it's an animation company, the video files can get rather large. Here's what I've done so far:

I recently watched: YouTube - Create a Website File Upload System (Part 1) (Create a Website File Upload System) and I did everything exactly as explained in the video. However when I test this out I get the error "HTTP error: with Pic 05.jpg :error #401". I noticed a comment stating that it could be a permissions thing, however I used FileZilla to change the permissions for the public_html folder to 0777 (everything on). This still did not fix the issue. I use HostGator same as the person in the video.

Any ideas on how to fix this? Or a better method for what I'm trying to accomplish?
 
You'd need to post the upload code for us to help out. It doesn't sound like a permissions error. More of a file handler error.
 
PHP:
[COLOR="red"]Here is the PHP Script code titled upload.php[/COLOR]

<?php

	if (is_uploaded_file($_FILES['Filedata']['tmp_name']))	 {

		$uploadDirectory = "uploads/";
		$uploadFile = $uploadDirectory . basename($_FILES['Filedata']['name']);
				
		copy($_FILES['Filedata']['tmp_name'], $uploadFile);
		
	}
?>

[COLOR="red"]And here is the code for the .swf file[/COLOR]

//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;

//a small function to redraw (reset) the progress bar
function reDrawPB (pb, xCor, yCor) {
	_root.destroyObject(pb);
	_root.createObject("ProgressBar",pb,0);
   	_root.progressBar.move(xCor,yCor);
}
	

//===================== COMBO BOX EVENT HANDLER =====================//

myComBoxListener.change = function(obj) {
	fileType = obj.target.selectedItem.label
	
	switch (fileType) {
		case "Image Files": 
			fileDescription = "Image Files";
			fileExtension = "*.jpg; *.jpeg; *.gif; *.png";
			reDrawPB ("progressBar", 215.9, 128);
			break;
		case "Video Files": 
			fileDescription = "Video Files";
			fileExtension = "*.mov; *.wmv; *.avi; *.mp4";
			reDrawPB ("progressBar", 215.9, 128);
			break;
		case "Audio Files": 
			fileDescription = "Audio Files";
			fileExtension = "*.wav; *.mp3;";
			reDrawPB ("progressBar", 215.9, 128);
			break;
		case "Text Files":
			fileDescription = "Text Files";
			fileExtension = "*.txt; *.rtf; *.doc; *.fdx; *.pdf";
			reDrawPB ("progressBar", 215.9, 128);
			break;
		case "Zip Files":
			fileDescription = "Zip File";
			fileExtension = "*.zip";
			reDrawPB ("progressBar", 215.9, 128);
			break;
		default:
			isDefault = true;
			trace (isDefault);
			break;
	}
	
	status_txt.vPosition = status_txt.maxVPosition;
	
	if (isDefault == true) {
		//if user select the file type option it will clear the text area
		status_txt.text="";
		browseButn.enabled = false;
		isDefault = false;
	}else {
		status_txt.text = fileDescription + ' ' + '('+fileExtension+')'+'\n';
		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";
}

//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 {
	//setting the status bar function
	progressBar.mode = "manual";
	progressBar.setProgress(bytesLoaded, bytesTotal);
}

//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;
}

//********************************* 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}]);

}

//Button event for the upload button
uploadButn.clickHandler = function () {
	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
	fileRef.upload("http://www.mywebsite.com/uploadsystem/upload.php");
}

Both the PHP and .swf file are under the same directory /uploadsystem and I want all uploaded files to go to the directory /uploadsystem/uploads. I didn't change any code in the PHP file, because they video said that it was set by default to send files to the /uploads directory.
 
Use PHP tags to hold your code for future reference.

You've created the uploads directory already? I also noticed your form at the bottom still has mywebsite.com. You changed that right?

If you've done the above, try using this instead of the copy function:
PHP:
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
 
Sorry about the PHP box, I didn't notice that. First time using this forum hehe.

As for the directories, yes they are already created and the website was already set to my actual URL. Since it is a private site I didn't wanna post it here on the forums.

I will try to change the code a bit later and let you know how it goes.
 
Use PHP tags to hold your code for future reference.

You've created the uploads directory already? I also noticed your form at the bottom still has mywebsite.com. You changed that right?

If you've done the above, try using this instead of the copy function:
PHP:
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);

Tried this code, still get the same error code.
 
It's definitely something missing in your form then.

Unfortunately Flash is the weakest of all my language skills as I barely have any use for it over Javascript so I can't help you very much.
 
Bumber, well any suggestions other than the flash .php method? I don't really care how I upload files, I just need to be able to. Flash was just the fancier method and looks better, but I'd be willing to do w/e.
 
Status
Not open for further replies.
Back
Top Bottom