dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] FLASH ARCHIVE UPLOADED, problem renaming files

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    Argentina
    Posts
    130

    [F8] FLASH ARCHIVE UPLOADED, problem renaming files

    Ok i have this part of the application that lets the user upload his archives to in this case (my localhost) server (testing for now...)

    Everything works great, the image files (in this case) are uploading just fine...
    But im having some trouble renaming the files (giving a new value from flash) when the images are saved...they are saved but with no name at all...not with the value that i assigned from flash in this case: "testerUser"

    FLASH CODE: (it looks long...but you just have to read the final part...i commented starting from where

    Code:
    //PICTURE UPLOAD SECTION:
    //ALL OF THIS IS JUST HOW IT WORKS...WHICH WORKS FINE...GO DOWN...
    //Allow this domain
    System.security.allowDomain("http://localhost/Test/phpAndMysql/flash%20user%20admin%201.4/images/", "127.0.0.1");
    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
    	txtStatus.text = "";
    	// Flash is attempting to upload the image.
    	txtStatus.text += "Attempting to upload "+selectedFile.name+"\n";
    	// Upload the file to the PHP script on the server.
    	selectedFile.upload("http://localhost/Test/phpAndMysql/flash%20user%20admin%201.4/upload.php");
    };
    // the file is starting to upload.
    listener.onOpen = function(selectedFile:FileReference):Void  {
    	txtStatus.text += "Uploading "+selectedFile.name+"\n";
    };
    //Possible file upload errors
    listener.onHTTPError = function(file:FileReference, httpError:Number):Void  {
    	txtStatus.text = "error";
    	txtStatus.text = "HTTPError number: "+httpError+"\nFile: "+file.name;
    };
    listener.onIOError = function(file:FileReference):Void  {
    	txtStatus.text = "error";
    	txtStatus.text = "IOError: "+file.name;
    };
    listener.onSecurityError = function(file:FileReference, errorString:String):Void  {
    	txtStatus.text = "error";
    	txtStatus.text = "SecurityError: "+SecurityError+"\nFile: "+file.name;
    };
    var imageFile:FileReference = new FileReference();
    imageFile.addListener(listener);
    btnUploadPicture.onPress = uploadImage;
    imagePane.addEventListener("complete", imageDownloaded);
    //READ FROM HERE------------------------> HERE MIGHT BE THE PROBLEM
    //send userId to php
    btnUploadPicture.onRelease = function() {
    	content_lv.userName = "testerUser";
    	content_lv.sendAndLoad("http://localhost/Test/phpAndMysql/flash%20user%20admin%201.4/upload.php", content_lv, "POST");
    };
    // Call the uploadImage() function, opens a file browser dialog.
    function uploadImage(event:Object):Void {
    	imageFile.browse([{description:"Image Files", extension:"*.jpg;*.gif;*.png"}]);
    }
    PHP CODE:

    PHP Code:
    //get nickname
    $userName=$_POST['userName'];
    //$userName="tester"; <----IF I ENABLE THIS, FROM PHP IT WORKS! SAVES THE IMAGE WITH THE NAME "TESTER" BUT FROM FLASH IT SAVES IT WITH NO NAME AT ALL

    $target "images/";
    list(
    $filename$extension) = explode('.'basename($_FILES['Filedata']['name']));
    //$filename = sha1($filename);
    $filename $userName;
    $target $target $filename "." $extension;

    $name=$_POST['name'];
    $pic=($_FILES['photo']['name']); 

    //create the directory if doesn't exists (should have write permissons)
    if(!is_dir("./images")) mkdir("./images"0755); 
    //move the uploaded file
    move_uploaded_file($_FILES['Filedata']['tmp_name'], $target); 
    ANY IDEAS???

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Looks to me you have 2 separate calls to php: first with filename and then with actual image file. However, variables are unique in php for each session meaning filename is deleted from memory before image file will be saved.

    You could perhaps add filename in the end of php call when you upload the image or if you want 2 calls to php you could save the value of filename in separate file so it can be accessed later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center