In my web application I need to upload images from my system and use it in Yiistrap carausel. I copied the image into my images directory and gave the address .But its not recognizing , its not showing the image although I gave the correct adress of my image
My code for using the image in Yiistrap widgets.
<?php echo TbHtml::carousel(array(
array('image' => '/var/www/store3/images/download.jpg/830x477', 'label' => 'First Thumbnail label', 'caption' => 'image1'),
array('image' => '/var/www/store3/images/download1.jpg/830x477', 'label' => 'Second Thumbnail label', 'caption' => 'image2'),
)); ?>
I also tried all combinations by removing the full path naming ,adding the relative path , but nothing seems to work .
The error I am getting is..
Failed to load resource: the server responded with a status of 404 (Not Found)
Any body kindly help me with this .I am stuck up
Try this. It worked at my end. Using Yii's baseurl is the best way to reference directories.
<?php echo TbHtml::carousel(array(
array('image' => Yii::app()->request->baseUrl.'/images/download.jpg', 'label' => 'First Thumbnail label', 'caption' => 'image1'),
array('image' => Yii::app()->request->baseUrl.'/images/download1.jpg', 'label' => 'Second Thumbnail label', 'caption' => 'image2'),
)); ?>
Related
Image file attachments in mandrill api working fine. But here,
'type' => 'image/jpeg',
'name' => "", // Here I didn't know what I am use
'content' => base64_encode(file_get_contents($img))
You can do something like
'name' => basename($img)
if you do not want to rename the image.
Hope this helps,
Ive been trying to upload an image file into my data base which as the attribute image_name. I want to be able to store the image and then store its file path into my database.. Ive tried many options on here.. but can't seem to figure out how to do it...
This is what I've got so far if anyone could point me in the right direction that would be great...
Thanks
Model -
public function attributeLabels()
{
return array(
'id' => 'ID',
'movie_name' => 'Movie Name',
'studio_id' => 'Studio',
'country_id' => 'Country',
'movie_rating_id' => 'Movie Rating',
'map_pin_id' => 'Map Pin',
'description' => 'Description',
'title_image' => 'Title Image',
'title_trailer_youtube_code' => 'Title Trailer Youtube Code',
'release_date' => 'Release Date',
'bg_colour_code' => 'Bg Colour Code',
'text_colour_code' => 'Text Colour Code',
'is_released' => 'Is Released',
'is_advanced_booking_allowed' => 'Is Advanced Booking Allowed',
'advanced_booking_start_date' => 'Advanced Booking Start Date',
'advanced_booking_end_date' => 'Advanced Booking End Date',
'domain_prefix' => 'Domain Prefix',
'facebook_app_id' => 'Facebook App',
'facebook_app_url' => 'Facebook App Url',
'facebook_icon_image_url' => 'Facebook Icon Image Url',
'facebook_text' => 'Facebook Text',
'twitter_text' => 'Twitter Text',
'booking_share_text' => 'Booking Share Text',
'home_tracking_url' => 'Home Tracking Url',
'shows_tracking_url' => 'Shows Tracking Url',
);
}
Controller -
public function actionCreate()
{
$model=new Movie;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Movie']))
{
$model->attributes=$_POST['Movie'];
$uploadedFile=CUploadedFile::getInstance($model,'title_image');
$fileName = $uploadedFile;
$model->title_image = $fileName;
if($model->save())
$uploadedFile->saveAs('http://localhost:8888/MY/Movies/title_image/'.$fileName);
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Reading your code, uploadedFile->saveAs() method expect full path to the file, not url.
To get full path, try with this:
$uploadedFile->saveAs(Yii::getPathOfAlias('webroot').'/images/uploaded/'.$fileName);
In this example images dir should be at same level as protected dir (only if images dir is being used for display public images through url):
assets/
images/
protected/
themes/
If you are on Unix environment, make sure to give proper read/write access to images dir.
If doesn't work, review this useful sample tutorial step by step that helps to introduce to file uploading with Yii.
How are you supposed to prevent the CMultiFileUpload widget from appending the file names of selected files to the page?
Here is my code:
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'images',
'accept' => 'jpeg|jpg|gif|png',
'denied' => 'Invalid file type',
'htmlOptions' => array('multiple'=>'multiple'),
));?>
Here is a picture of what I am talking about:
I need to remove what the arrows point to. It's also strange why it says "No files selected" when that isn't the case. If I submit the form, the file does indeed get sent to the server.
Edit:
It does what I want if javascript is turned off though. It also fixes the "no files selected" error. Is there a way to disable the javascript for just the widget?
if you want to hide the names of the files you have uploaded then you can use the options in your CMultiFIleUpload
eg:-
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'images',
'accept' => 'jpeg|jpg|gif|png',
'denied' => 'Invalid file type',
'htmlOptions' => array('multiple'=>'multiple'),
'options'=>array(
'onFileAppend'=>'
function(e,v,m)
{
// try using e.preventDefault();
(".MultiFile-label").css("display","none");
}
'
)
));?>
Note:- I haven't tested it but hope it helps.
I'm using cakephp-upload plugin of jose gonzalez to upload images to our app. By default, they're being saved in a directory like this: webroot/files/user/photo/{user_id} which is fine, except for when we want to display such images using $this->Html->image() which searches for images in the webroot/img directory.
I have already tried to display the images with
echo $this->Html->image('../files/user/photo/' .
$user['User']['photo_dir'] . '/' .
$user['User']['photo']);
which works but I was wondering if there's some way to tell this plugin to save into the img directory? The documentation doesn't mention any of that.
And also, is there any way to tell the $this->Form->input('User.photo', array('type' => 'file')); to accept only image files?
as you can see in this file, path is set like:
public $defaults = array(
'rootDir' => null,
'pathMethod' => 'primaryKey',
'path' => '{ROOT}webroot{DS}files{DS}{model}{DS}{field}{DS}',
...
you could change it to make:
'path' => '{ROOT}webroot{DS}img{DS}'
and for your second question, you could use accept attribute, like:
$this->Form->input('User.photo',
array(
'type' => 'file',
'options' => array('accept' => 'image/*')
)
);
I am adding functionality to post to a visitors Facebook wall.
I am using the following code:
$path_to_image = "http://projects.kleelof.com/boot_designer/image_interchange.php?c=" . $file_id;
$attachment = array('message' => 'this is my message',
'name' => 'The name of your company',
'caption' => "Caption of the Post",
'link' => $path_to_image,
'picture' => $path_to_image,
'description' => 'this is a description',
'access_token' => $facebook->getAccessToken()
);
//echo($path_to_image);
$result = $facebook->api('/me/feed/','post',$attachment);
The post appears on my wall, but not the image.
You can see the full process and post it makes by trying the app at: http://projects.kleelof.com/boot_designer - Then select either one of the 2 links.
take care,
lee
I think the path to the image needs to be and actual file system path, and the image will be read and uploaded along with the request for FB to process. Also, it needs to start with a # to actually upload it.