abedi98
(Abedi98)
November 5, 2012, 7:32am
1
hi friends
how to get image uploaded path in xupload etention ?
HomeController.php
class HomeController extends Controller
{
public function actions()
{
return array(
'upload'=>array(
'class'=>'xupload.actions.XUploadAction',
'path' =>Yii::app() -> getBasePath() . "/../uploads",
'publicPath' => Yii::app() -> getBaseUrl() . "/uploads",
),
);
}
function actionEditUser($id)
{
$model = User::fetchUserData($id);
$upload = new XUploadForm;
//.... any code
$this->render('back/editUser',array('model'=>$model, 'perm'=>$permission, 'listAccess'=>$listAccess, 'upload' => $upload));
}
}
views/home/editUser.php
<?php
$this->widget('xupload.XUpload', array(
'url' => Yii::app()->createUrl("cpanel/home/upload", array("parent_id" => 1)),
'model' => $upload,
'attribute' => 'file',
'multiple' => true,
));
?>
I then uploaded the photo URL into the text box !
xahgmah
(Xahgmah)
November 5, 2012, 10:42am
2
You must add subfolder var
public function actions()
{
return array(
'upload'=>array(
'class'=>'xupload.actions.XUploadAction',
'path' =>Yii::app() -> getBasePath() . "/../uploads",
'publicPath' => Yii::app() -> getBaseUrl() . "/uploads",
'subfolderVar' => 'parent_id'
),
);
}
When I installed this plugin. It doesn’t show uploaded images. And I had change plugins code
xupload/actions/XUploadAction.php
In "run" function
...
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$model = new XUploadForm;
$path = (($this->_subfolder != "") ? ("{$this->path}/{$this->_subfolder}/") : "{$this->path}/") . Yii::app()->request->getQuery($this->subfolderVar, date("mdY")) . "/";
$publicPath = (($this->_subfolder != "") ? ("{$this->publicPath}/{$this->_subfolder}/" . Yii::app()->request->getQuery($this->subfolderVar, date("mdY"))) : "{$this->publicPath}/") . Yii::app()->request->getQuery($this->subfolderVar, date("mdY")) . "/";
$result = array();
if (is_dir($path)) {
foreach (scandir($path) as $file) {
if ($file != "." && $file != ".." && strpos($file, "th_") !== 0 && strpos($file, "thb_") !== 0) {
$info = getimagesize($path . $file);
$filesize = filesize($path . $file);
$result[] = array(
"name" => $file,
"type" => $info['mime'],
"size" => $filesize,
"url" => $publicPath . $file,
"thumbnail_url" => $this->getThumbnailPath($publicPath, $file),
"delete_url" => $this->getController()->createUrl("upload", array(
"_method" => "delete",
"file" => $path . $file
)),
"delete_type" => "POST"
);
}
}
echo json_encode($result);
}
} else {
if (isset($_GET["_method"])) {
...
abedi98
(Abedi98)
November 5, 2012, 11:13am
3
how to echo filename after upload !?
xahgmah
(Xahgmah)
November 5, 2012, 11:34am
4
This plagin send image data like json array using ajax. Look to my code above, and you will see this array, and its parrameters ($result);
You can change XUpdloadAction code to your need
forbes17
(Artem)
August 11, 2013, 1:54pm
5
Could you help me to solve one problem?
I managed to setup XUpload correctly, and it loads images and moves them to the proper folder. But I can’t load existing photos on Edit page. Do you have any ideas?