Post A File To Antoher Website

I’d like to post a file to anther website. Traditionally, we can do,

<form action="http_website" method="post">



How to do this in YII please? I am new to Yii and am reading Larry’s book now.

Thanks a lot.

you can also use CURL to do this, sample code pasted below


// URL on which we have to post data

$url = "http://localhost/tutorials/post.php";

// Any other field you might want to post

$json_data = json_encode(array("name"=>"PHP Rockstart", "age"=>29));

$post_data['json_data'] = $json_data;

$post_data['secure_hash'] = mktime();

// Initialize cURL

$ch = curl_init();

// Set URL on which you want to post the Form and/or data

curl_setopt($ch, CURLOPT_URL, $url);

// Data+Files to be posted

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

// Pass TRUE or 1 if you want to wait for and catch the response against the request made

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// For Debug mode; shows up any error encountered during the operation

curl_setopt($ch, CURLOPT_VERBOSE, 1);

// Execute the request

$response = curl_exec($ch);

// Just for debug: to see response

echo $response;

good point !

Thanks a lot for the quick reply. I am very new to Yii. Where should I put these codes?

Suppose I have a view for a list of files.

I should put :

$output = Yii::app()->curl->post($url, $data);

to my model? And how to call it from view php file?

Thanks a lot.

You can place these code on your controller action.

the same can be achieved using this extension