7 Replies Latest reply on Dec 29, 2006 9:20 AM by jonnybennett

    return renamed uploaded file name

    JayCeeBE
      Hey,

      I'm trying to upload a file from flash(selected via filereference) via php, i rename(in php) the file before uploading it. this isn't a problem and works great but then i need to return the new filename to flash so i can save a link to it in my database.

      my biggest problem is that i use file.upload(phpScriptPath) to upload the file. But if i use the echo command in php to return newFilename i don't know how to capture this information in flash.

      does anybody help me out?

      thx on advance
        • 1. Re: return renamed uploaded file name
          Peter Lorent Level 2
          You can't return the new filename using the FileReference object so you need a workaround. From what you posted here I can't put my finger on the right solution but to illustrate:
          I needed a solution as part of a form where the user would provide name, email and so on and could upload a c.v. Before the file upload I used a LoadVars (and used the sendAndLoad() method) object to post the data from the form and return the record_id from the database. In the onLoad event of the LoadVars object I used the FileReference object to handle the upload, calling an upload script and added the record_id as a get variable. The record_id was then used to save the new filename of the uploaded file to the database.
          If this is not feasible in your situation, elaborate on the topic by describing your scenario in more detail.

          • 2. Re: return renamed uploaded file name
            JayCeeBE Level 1
            hmm gonna try this now.
            I think it should work for me as well but I'll get back to you.

            Thanks for your reply.
            • 3. Re: return renamed uploaded file name
              JayCeeBE Level 1
              hmm seems to be working. the downside of this method is that if for some reason the upload would fail i would still have the information in my database but i'll find a workaround for that as well :-)

              thanks for your help
              • 4. Re: return renamed uploaded file name
                Peter Lorent Level 2
                Once you have the record_id in Flash, you can use the events of the FileReference object and again use a LoadVars object there to delete the record from the database.
                • 5. Re: return renamed uploaded file name
                  JayCeeBE Level 1
                  I know, but that way i'll have to talk to my db 2 times instead of 1.

                  Since this is my first time developping for a pretty big amount of visitors (+-30 000/month) and i don't really have an idea how this will affect my db speeds i'm trying to limit the communications between flash and my db.

                  Do you have any remarks or hints for using the filereference object or database communication with this amount of users?
                  • 6. Re: return renamed uploaded file name
                    Peter Lorent Level 2
                    True, but that's only going to happen when the upload fails.

                    Assuming you use a real database, that amount of visitors shouldn't be a problem. When it comes to 30,000 a day...
                    • 7. Re: return renamed uploaded file name
                      jonnybennett Level 1
                      You could rename the file in flash. Then send the new name to your php script using GET

                      newFilename=jack302341.jpg;

                      file.upload(myUploadScript.php?newFile=newFilename)