Install ckeditor in YII framework - yii

I am using Yii Framework version 1.1.14. I am able to install FCK editor but I want to use ck editor.
I download files from this links http://www.yiiframework.com/extension/the-ckeditor-integration/
and upload files on location but i get this error
check image
I am using this code in my view
<?php $this->widget('application.extensions.ckeditor.CKEditorWidget',array(
'model'=>$model, # Data-Model (form model)
'attribute'=>'content', # Attribute in the Data-Model
'height'=>'400px',
'width'=>'100%',
'toolbarSet'=>'Basic', # EXISTING(!) Toolbar (see: ckeditor.js)
'ckeditor'=>Yii::app()->basePath.'/../ckeditor/ckeditor.php',
# Path to ckeditor.php
'ckBasePath'=>Yii::app()->baseUrl.'/ckeditor/',
# Relative Path to the Editor (from Web-Root)
'css' => Yii::app()->baseUrl.'/css/index.css',
# Additional Parameters
) ); ?>

Download CKEditor from http://ckeditor.com/download (Select full package) and put it in your root directory (You can put it any where according to you)
Add this is your view file
<script src="<?php echo Yii::app()->baseUrl.'/ckeditor/ckeditor.js'; ?>"></script>
<script type="text/javascript">
CKEDITOR.replace( 'Articles_meta_description');
</script>
Where Articles_meta_description is id of input fields
If you want add image upload in ckeditor you can download KCfinder from this link http://kcfinder.sunhater.com/download and put it in your root directory (you can put it any where according to you)
Set upload path into session : in your view file
$_SESSION['KCFINDER']['disabled'] = false; // enables the file browser in the admin
$_SESSION['KCFINDER']['uploadURL'] = Yii::app()->baseUrl."/uploads/"; // URL for the uploads folder
$_SESSION['KCFINDER']['uploadDir'] = Yii::app()->basePath."/../uploads/"; //
For ckeditor with image upload
<script type="text/javascript">
CKEDITOR.replace( 'Articles_meta_description', { // input field id
filebrowserBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=files',
filebrowserImageBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=images',
filebrowserFlashBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=flash',
filebrowserUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=files',
filebrowserImageUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=images',
filebrowserFlashUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=flash'
});
</script>

Related

create my own directory in html with download links

I was trying to create an online webshare but i'm unable to make a page which will automatically add or remove files from the site when done so. Please help me in resolving this problem. And I'm not able to link the PHP code to the html page to execute, please help me in creating the html and PHP in my already built design pages so that i can complete my project.
The Php Of The Page Goes As Follows
<html>
<body style="background:#e9e9e9; font-family:Verdana; font-size:180%">
<head>
<p style="text-align:center; size:20%">Download Now!
<br>No Need of Internet!</p>
</head>
<div style="background:white; margin-right:2%; margin-left:2%; font-size:150%">
<font color="cornflowerblue">Owais</font> shared some files with you.
<hr>
Files
<hr>
<?php
if ($handle = opendir('C:\Users\makro\Documents\Share\Send')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$thelist .= '<li>'.$file.'</li>';
}
}
closedir($handle);
}
?>
<h1>List of files:</h1>
<ul><?php echo $thelist; ?></ul>
</div>
</body>
</html>

Yii2: How to use backend web folders files in frontend

I have many images in backends web folder, I want to use those images in frontend how to get those files?
I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg;
<?php
foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img)
{
?>
<?php echo Html::img('#backend/web'.'/'.$value_img);?>
<?php
}
?>
<?= \yii\helpers\Html::img('#backend/web/images/your-image.jpg') ?>
The src parameter, containing the backend alias, will be processed by Url::to()
Check the docs for details on Html::img().
Simply try:
<?= \yii\helpers\Html::img( Yii::getAlias('#backend'). '/web/images/your-image.jpg') ?>

Opencart - Upload Specific File Type

I am using OpenCart 1.5.6 and have two options for the customer to upload files to a product (image and video). When the users clicks upload I would like them to only be able to select specific file types from their computer while they browse for the files. So instead of "All Files" in the browser window, I want it to only allow .png, .jpg, .jpeg, .pdf, etc. for the image upload and for the video file I just want it to look for .mp4, .mov, .flv.
Here is an example: http://jsfiddle.net/VCdvA/
I have tried to use the accept attribute according to this post but it doesn't work.
Here is my code for the product.tpl:
<input type="button" accept="video/*,image/*" value="<?php echo $button_upload; ?>" id="button-option-<?php echo $option['product_option_id']; ?>" class="button" >
<input type="hidden" name="option[<?php echo $option['product_option_id']; ?>]" value="" />
I think that the problem is that it is type="button" and not type="file". Is there another way to limit the upload file type within the OpenCart product page?
The problem is the jQuery plugin used. It is AjaxUpload which seems to be taken over by different developer (completely) and reworked (completely) and the links to the original (old) documentation are dead (completely).
Well, after exploring that jQuery plugin I have found out that it works this way: in the ptoduct.tpl You can see:
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'file') { ?>
<script type="text/javascript"><!--
new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', {
//...
});
//--></script>
<?php } ?>
<?php } ?>
This means that for each option of type file this AjaxUpload is instanciated. Basically it only creates a DIV containing INPUT of type FILE with 0 opacity that is rendered above the Upload File button. This means that when user clicks on Upload File he clicks on the INPUT of type FILE instead (without knowing this). Now, looking at the code I can see that there is no possibility to set this accept="image/*" attribute because there is no support for this (original code):
_createInput: function(){
var self = this;
var input = document.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
addStyles(input, {
// ...
});
// ...
},
So now if You'd like to add support for this, You'd need to change this code to this (file: catalog/view/javascript/jquery/ajaxupload.js, around line 350):
var input = document.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
if (this._settings.accept) {
input.setAttribute('accept', this._settings.accept);
}
And change the code for plugin initializiation in product.tpl to:
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'file') { ?>
<script type="text/javascript"><!--
new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', {
<?php if ($option['product_option_id'] == <IMAGE_FILE_OPTION_ID>) { ?>
accept: 'image/*',
<?php } else if ($option['product_option_id'] == <VIDEO_FILE_OPTION_ID>) { ?>
accept: 'video/*',
<?php } ?>
//...
});
//--></script>
<?php } ?>
<?php } ?>
This should be enough.

show uploaded image yii

I am new to php and yii. I have a file field in my form to upload images. I use the following code to upload the image using file field.
Code in View:
<?php echo $form->fileField($model,'logo', array('class'=>'input-file')); ?>
<img src="<?php
echo Yii::app()->request->baseUrl.'/protected/uploads/sitelogo/'.$savedvalues['varLogo'];
?>" width="50" height="50" />
<?php echo $form->hiddenField($model,'hiddenfile',
array('value'=>$savedvalues['varLogo'])); ?>
code in controller:
$randnum = rand(0,100);
$home->varLogo = $randnum.$model->logo;
$file= Yii::app()->getBasePath().'/uploads/sitelogo/'.$randnum.$model->logo;
$model->logo->saveAs($file);
The images are uploading fine now. I have saved the uploaded images in protected\uploads\ folder. I am trying to show the uploaded image in edit image section. But the image doesn't display. It Shows failed to load the given url in firebug.
How can i correct this issue?
protected folder is protected for some reason - nobody can access it
if you want to access your pictures move them to public folder (or public/uploaded)
here is .htaccess content for protected
deny from all
EDIT:
of course you can put your files into protected folder(or make uploaded folder not accessible too) if you want some ACL for your users, and then check access, read and output file by your script(class)
in view:
<img src="<?php
echo Yii::app()->request->baseUrl.'/image.php?url=protected/uploads/sitelogo/'.$savedvalues['varLogo'];
?>" width="50" height="50" />
in your controller or class:
if (Yii::app()->session['user_can_access_files']) {
header('Content-Type: image/jpeg');
readfile($_GET['url']);
} else {
Yii::app()->user->loginRequired();
}
Caveat: I'm a total yii noob, so take this w/ a grain of salt :)
I took a similar approach, but have user-specific folders & added a MIME type check.
I upload files in a similar way, then view them with this in the view:
echo '<embed src="/tim_0.5/index.php/files/Getdatafile/' . $modelid . '" width=100% height=400>';
And from my controller I have:
public function actionGetdatafile($id)
{
$model=$this->loadModel($id);
$imgpath = $model->user_id . '/' . $model->filename;
$file=Yii::app()->getBasePath().'/datafiles/'.$imgpath;
if (file_exists($file))
{
$img=getimagesize($file);
header('Content-Type: '.$img['mime']);
readfile($file);
exit;
} else {
echo 'File not found!';
}
}
<b><?php echo CHtml::encode($data->getAttributeLabel('binaryfile')); ?>:</b>
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/upload/'.$data->fileName); ?>
<br />
filename is name of your file which you have stored in upload folder in root directory.
(Yii::app()->request->baseUrl.'/upload/' point to your upload folder which is in your root directory
Hope it works....

I am unable to upload file to my local host folder in php

I have the follwing code
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
my page is in http://local.host/nausal/upload.php
now I am having the follwing error though i have created a folder in site with name upload.
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 15
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 17
Sorry, there was a problem uploading your file.
If the form is a part of upload.php too, you need to encapsulate the PHP-code and first check if $_FILES is not empty, otherwise you will always get a Notice if you only want to display the form.
<?php
if(!empty($_FILES))
{
//your PHP-code here
}
?>
<!-- your form here -->
Khan sb Place this code in file
called upload.php
create a folder called upload where
you created upload.php
change echo "The file ". basename(
$_FILES['uploadedfile']['name']). "
has been uploaded"; to echo "The
file ". basename(
$_FILES['uploaded']['name']). " has
been uploaded";
This will upload file successfully. First time when upload.php is uploaded there is no file selected so you will see some errors. But after you select a file and click upload you will not see any error. To avoid this error do as suggested by Dr. Molle