# Upload and view images

**URL:** <https://forum.kirupa.com/t/upload-and-view-images/214679>\
**Category:** Uncategorized\
**Created:** [January 31, 2007, 1:51am UTC](https://forum.kirupa.com/t/upload-and-view-images/214679 "2007-01-31T01:51:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![foevah](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@foevah](https://forum.kirupa.com/u/foevah)\
**Post date:** [January 31, 2007, 1:51am UTC](https://forum.kirupa.com/t/upload-and-view-images/214679/1 "2007-01-31T01:51:57Z")

</div>

I’ve tried a few tutorials and none have been successful. One being kirupa’s [http://www.kirupa.com/developer/flash8/uploading\_fileReference\_pg1.htm](http://www.kirupa.com/developer/flash8/uploading_fileReference_pg1.htm)  
What happened with this the file uploaded but I couldnt view it… I didnt know where it uploaded it… I made the files folder and added the php page but I cant figure out why it doesnt work.  
Heres the link to my attempt at kirupa’s file uploader:  
[http://www.jamesgardner.lincoln.ac.uk/flash\_uploader/fileUploader.swf](http://www.jamesgardner.lincoln.ac.uk/flash_uploader/fileUploader.swf)  
When you upload a file I assume it should go into this folder:  
[http://www.jamesgardner.lincoln.ac.uk/flash\_uploader/uploads/](http://www.jamesgardner.lincoln.ac.uk/flash_uploader/uploads/)

This is the php used on upload.php

```php
<?php
 if (is_uploaded_file($_FILES['Filedata']['tmp_name'])){

    $uploadDirectory="http://www.jamesgardner.lincoln.ac.uk/flash_uploader/uploads/";
    $uploadFile=$uploadDirectory.basename($_FILES['Filedata']['name']);
                
    copy($_FILES['Filedata']['tmp_name'], $uploadFile);
        
 }
?> 

```

This is the tutorial im curreny trying: [http://www.flash-db.com/Tutorials/upload/](http://www.flash-db.com/Tutorials/upload/)

You can see my latest attempt at this url  
[http://www.jamesgardner.lincoln.ac.uk/upload\_flash8/upload.swf](http://www.jamesgardner.lincoln.ac.uk/upload_flash8/upload.swf)

I dont know why I cant get it to work… Ive got access to cpanel and im not sure how to give the folder file permissions. This being said Ive got CHMODD 777 on the upload\_flash8 folder and when you go to upload.php  
([http://www.jamesgardner.lincoln.ac.uk/upload\_flash8/upload.php](http://www.jamesgardner.lincoln.ac.uk/upload_flash8/upload.php))  
theres this error:  
**Warning** : chmod(): Operation not permitted in **/home2/jamesgar/public\_html/upload\_flash8/upload.php** on line **6**

If anyone knows how to get this working then please let me know!

the upload.php script is:

```php
 <?php
//create the directory if doesn't exists (should have write permissons)
if(!is_dir("./files")) mkdir("./files", 0755); 
//move the uploaded file
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
chmod("./files/".$_FILES['Filedata']['name'], 0777);
?>

```

the action script on upload.swf is:

```auto
//Allow this domain
System.security.allowDomain("http://localhost/");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();

// When the user selects a file, the onSelect() method is called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void {
  //clean statusArea and details area
  statusArea.text = details.text = ""
  // Flash is attempting to upload the image.
  statusArea.text += "Attempting to upload " + selectedFile.name + "
";
  // Upload the file to the PHP script on the server.
  selectedFile.upload("upload.php");
};

// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
  statusArea.text += "Uploading " + selectedFile.name + "
";
};
//Possible file upload errors
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "HTTPError number: "+httpError +"
File: "+ file.name;
}

listener.onIOError = function(file:FileReference):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "IOError: "+ file.name;
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
    imagePane.contentPath = "error";
    imagePane.content.errorMSG.text = "SecurityError: "+SecurityError+"
File: "+ file.name;    
}

// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
  // Notify the user that Flash is starting to download the image.
  statusArea.text += "Upload finished.
Now downloading " + selectedFile.name + " to player
";
  //Show file details
  details.text = ""
  for(i in selectedFile) details.text +="<b>"+i+":</b> "+selectedFile*+"
"
  // Call the custom downloadImage() function.
  downloadImage(selectedFile.name);
};

var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);

uploadBtn.onPress = uploadImage;
imagePane.addEventListener("complete", imageDownloaded);

// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
  imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}

// If the image does not download, the event object's total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
  if(event.total == -1) {
    imagePane.contentPath = "error";    
  }
}

// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
  imagePane.contentPath = "./files/" + file;
}

stop()

```
