hi,

My question is,i have used current state="temp" to display the
datagrid after i moved  the image.But the image will not displayed in
the datagrid  why because we have to refresh the page.

 Please help me to solve the problem.

Here the Flex script i have used to move the image.

 <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
creationComplete="init();userRequest.send();">
<mx:HTTPService id="userRequest" url="uploadFile.php" method="POST"
useProxy="false">

</mx:HTTPService>
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;

            private var urlRequest:URLRequest;
            private var fileReferenceList:FileReferenceList;
            private var serverSideScript:String = "uploadFile.php";

            private function init():void {
                urlRequest = new URLRequest(serverSideScript);
                fileReferenceList = new FileReferenceList();
                fileReferenceList.addEventListener(Event.SELECT,
fileSelectedHandler);
            }

            private function uploadFile():void {
                fileReferenceList.browse();

            }

            private function fileSelectedHandler(event:Event):void {
                var fileReference:FileReference;
                var fileReferenceList:FileReferenceList =
FileReferenceList(event.target);
                var fileList:Array = fileReferenceList.fileList;



                // get the first file that the user chose
                fileReference = FileReference(fileList[0]);

                // upload the file to the server side script
                fileReference.addEventListener(Event.COMPLETE,
uploadCompleteHandler);
                fileReference.upload(urlRequest);

                // update the status text
                statusText.text = "Uploading...";
            }

            private function uploadCompleteHandler(event:Event):void {
                statusText.text = "File Uploaded: " +
event.target.name;
                currentState="temp";
            }

        ]]>


    </mx:Script>

    <mx:Label text="Upload File From Flex to PHP" fontWeight="bold"/>
    <mx:Label text="Choose a file..." id="statusText"/>
    <mx:Button click="uploadFile();" label="Upload File"/>


The following query i have used in PHP

<?php

$con=mysql_connect("localhost","root","");
if(!$con){
    echo "Error in Connecting Database";
}
mysql_select_db("project",$con);

 $tempFile = $_FILES['Filedata']['tmp_name'];
$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];


$path="path/".$fileName;

move_uploaded_file($tempFile,$path);

if($fileName!=''){
$ins=$query=("insert into
tbl_image(img_id,img_name,img_status)values('','$fileName',1)");
mysql_query($ins);
}

$answer="select * from tbl_image";
$result=mysql_query($answer);
print "<users>";
while($row=mysql_fetch_object($result)){

    print "<user>
     <img>".$row->img_name."</img>

    </user>";
}
print"</users>";
?>

Here the following datagrid i have used to display the image.

 <mx:states>
    <mx:State name="temp">
    <mx:AddChild>
      <mx:DataGrid x="10" y="10" width="443" height="176"
dataProvider="{userRequest.lastResult.users.user}" id="dgPhoto">
                           <mx:columns>

                                    <mx:DataGridColumn
headerText="Preview" dataField="img">
                                    <mx:itemRenderer>
        <mx:Component>
        <mx:VBox>
        <mx:Image source="path/{data.img}" width="100%" height="100"
horizontalAlign="center"/>
        </mx:VBox>
        </mx:Component>
        </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
    </mx:DataGrid>
    </mx:AddChild>

    </mx:State>
    </mx:states>
    </mx:Application>

Please find me the solution to solve the problem.

Thanks and Regards,
venkat.R

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to flex_in...@googlegroups.com.
To unsubscribe from this group, send email to 
flex_india+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to