Link to home
Start Free TrialLog in
Avatar of Member_2_4768634
Member_2_4768634

asked on

How upload images to a PHP Server and save the path in a MYSQL DB

Hi Jones911,

please can you show me how i can upload images (jpg) to the server, with saving the path in the MYSQL DB. When the Popup with the User Details is open, i want to have the possibility to upload a user image. Is there a way to put a upload Button next the image.

Thanks again!!
Avatar of Jones911
Jones911

OK here is a Flex -> php file uploaded demo:  http://weblog.cahlan.com/2006/09/uploading-files-with-flex-and-php.html

So then you just need to link the image just uploaded to the selected item in the pop up.

So on success of the file upload call a method that updates that row in the database to reflect the file you just uploaded.


update    users
set       image_url = 'http://mydomain.com/images/user999.jpg'    //where user999.jpg is the image file you uploaded to /images
where     userid = '999'   // and this is the userid passed back from flex to update the db

Open in new window

Avatar of Member_2_4768634

ASKER

Thank´s for the link. I knew this sample, but there´s no PHP included. I don´t know how the PHP has to look like. And i don´t understand what you mean with "So then you just need to link the image just uploaded to the selected item in the pop up."

Thank´s!
After a while looking around on this site i have found the PHP example.
But please can you tell me how to configure the DOCUMENT_ROOT. My Application is a Desktop Version. And i have to upload the images on the Webserver. How will this work? Have i to write a FZP Workaround?

Thank´s
$file_path = $_SERVER['DOCUMENT_ROOT']."/myFileDir"; // http://www.serveradress.at/images/

Open in new window

DOCUMENT_ROOT is just a place on you webserver eg /var/www/virtual/mysite.com
Yes, i know. But if i upload an image from my Desktop to a webserver i will need an FTP connection. Or am i wrong?
No.  You can upload images as a post from flex.  No FTP needed.
Her is another sample: http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/

I can't help that much with the PHP code as I use Coldfusion but it seams liek its covered here. http://weblog.cahlan.com/files/php_fileuploads.html
Thank you for the examples.

For uploading images i need to put (creationComplete="initApp()") in the mx:TitleWindow. But i have allready one in it. (creationComplete="send_data()") what i need for my form. Please how can i handle 2 creationComplete Events?
And i get this Error:
SecurityError: Error #3207: Application-sandbox content cannot access this feature.

But, i think so, have define Security.allowDomain

Thank´s!
private function initApp():void {
                Security.allowDomain("*");
                _arrUploadFiles = new Array();
            }  

Open in new window

do you hev a crossdomain.xml file?
No i have not.
Its required here have a read you will have to set one up:  http://labs.adobe.com/wiki/index.php/Flex:Accessing_Data
OK thank you. I will try it immediately.
Do you know a solution relevant to the creationComplete please?
creationComplete="initApp();send_data()"   in the mxml

or at the top of

private function init():void{

    send_data();

    ...rest of method

}
Thank´s. The creationComplete works now.
Also i have created the crossdomain.xml and have it upload to the webserver. But the Error isn´t away.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.mydomain.at" />
</cross-domain-policy>

Open in new window

<allow-access-from domain="www.mydomain.at" />
  Is this the IP your at now or you serevr ip

for now just put *



<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.mydomain.at" />
</cross-domain-policy>

Open in new window


<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

Open in new window

I have changed it like you describe, but i get the Error. I have try to put the crossdomain.xml in the root of my server and in the folder where are all the PHP stored.
Place it in the folder where you callign the upload.php just to try.
Yes i have try this, but it doesn´t work. Could it be that it have something do with the DOCUMENT_ROOT defintion in the upload.php? I haven´t write a http URL but this: /home/.sites/148/site6/web/images

Thank´s!
No it just sits in the root of the website and allows flash client to connect.

Can you paste a screen shot of the exact error?
Here it is.
error.gif
whats on line 28 of kundenDetails.mxml
private function initApp():void {
                Security.allowDomain("*"); // line 28
                _arrUploadFiles = new Array();
            }
Get rid of:

private function initApp():void {
                Security.allowDomain("*"); // line 28
                _arrUploadFiles = new Array();
            }


make it like this:

private function initApp():void {
                   _arrUploadFiles = new Array();
            }
OK, now the Error ist away.
The upload Message is successfull, but no image reached the folder (images) on the webserver.

Please can i contact you tomorrow again? I haven´t sleep since 40 hours and i have to be in about 6 hours at work.

Thank´s a lot!!
ASKER CERTIFIED SOLUTION
Avatar of Jones911
Jones911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Jones911,

thanks for your help yesterday! Should i give you the 500 Points and close this Thread, to open a new one with again 500 Points?

OK, i have used your example (http://weblog.cahlan.com/files/file_uploads/FileUpload.html) but anything happen wrong. In the PHP i can define as DOCUMENT_ROOT what i want (right or wrong), everytime i get a successfull when i start a upload, but no image was upload to the webserver.

Please have you an idea?

Thank´s!
MXML:
-----------
private const _strUploadDomain:String = "http://www.mydomain.at/";
            private const _strUploadScript:String = _strUploadDomain + "folder_x/userfoto_upload.php";
 
 
PHP:
-----------
$file_path = $_SERVER['DOCUMENT_ROOT']."/home/.sites/148/site6/web/folder_x/images";

Open in new window

Try it like this:

$file_path = "/home/.sites/148/site6/web/folder_x/images";
Wow, thank´s - now it works.

I have started a new Thread because i haven´t know if you´re agreed with only 500 Points.

Please can you show me how the image holder in the User Details now know, what image he have to display. I don´t know how to write the path in the MYSQL DB.

Thanky you!!