I want to upload image from user form. But my code is not working. Please help me
My view code is here:
echo $this->Form->create('User',array('enctype'=>'multipart/form-data'));
echo $this->Form->input('cat_image',array('type'=>'file'));
echo $this->Form->end('Submit');
My Controller code is here:
move_uploaded_file($_FILES['tmp_name'], WWW_ROOT . 'img/uploads/' . $_FILES['cat_image']);
You have to add a 'type' tag to your form:
<?php echo $this->Form->create('User', array('type' => 'file'));?>
Then in the Controller do something like this:
if (is_uploaded_file($data['User']['image']['tmp_name']))
{
move_uploaded_file(
$this->request->data['User']['image']['tmp_name'],
'/path/to/your/image/dir/' . $this->request->data['User']['image']['name']
);
// store the filename in the array to be saved to the db
$this->request->data['User']['image'] = $this->request->data['User']['image']['name'];
}
And to View like this to show the image in webpage:
<?php echo $this->Html->image('/path/to/your/image/dir/' . $listShExPainImage['User']['image']); ?>
Let me know if i can help you more.
change
echo $this->Form->create('User',array('enctype'=>'multipart/form-data'));
to
echo $this->Form->create('User',array('type' => 'file'));
output
<form id="UserAddForm" enctype="multipart/form-data" method="post" action="/users/add">
Related
How do you perform translation with an embedded link_to function in the template using Symfony 1.4?
Example:
Please click <php echo link_to('here', sfConfig::get('app_url') ?> for additional info.
I usually do something like this:
echo __("Please click "%placeholder%", array("%placeholder%" => link_to(__("here"), sfConfig::get('app_url'))))
You can also use:
Please click <?php echo __('here') ?> for additional info
Or you can use:
Please click <?php echo link_to(__('here'), sfConfig::get('app_url') ); ?>
Is there any code for getting all exif data of an image?
I want all possible data that can be extraxted from an image file(which the user will upload on my webpage) like bitrate ,file owner and security details. Also,if there have been any comments added to the image,i want to get that too.
If an API exists to do these things for any file(video,text,image) then it will be really helpful.
Thank you,
Shubham
you can do this with php
example:
<?php
echo "test1.jpg:<br />\n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>
or there is a exif.js that will do it aswell
Hi everyone I have a modal windows in joomla 3.0!
I pass the router to javascript like this
<?php $link =JURI::root().'index.php?option=com_projects&view=proyectos&format=raw&task=todosProyecto&id='. $item->id;?>
<li class="item" data-id="id-<?php echo $item->id ?>" data-type="<?php echo $item->categoria ?>">
<a href="#modal" id="<?php echo $link;?>" role="<?php echo $item->id ?>" class="picture" data-toggle="modal">
<img src="<?php echo JURI::root()?><?php echo $item->imagen_portada; ?>"/></a>
<p class="titulo"><?php echo $item->nombre; ?></p>
<p> <?php echo $item->municipio; ?>(<?php echo $item->pais; ?>)<br><?php echo $item->year; ?>
</p>
In local when I open the modal windows it work well, but in the server the modal windows show me the index.php view of this component.
I think that my problem is here, when I take the request for the model I have this.
public function elegirSeleccionados(){
$this->pagination = $this->get('pagination');
$this->items = $this->get('recientes');
$this->list = $this->get('list');
parent::display();
}
But $this->get('list'); is null so I have to asigned a null value to list.
I changed by that..
$this->list = $this->items;
but dont work to!
Any idea!!!
Where is this code?
First part looks like a Layout (views\proyectos\tmpl\default.php) and the second one like a View (views\proyectos\view.html.php).
If it is so, I'd say you are not really loading items in View from the Model. Try using $this->items = $this->get('Items');
But this doesn't explain different results on server and local host.
Hi everyone I solved the problem... the name of my view hava a Camelcase for example itemId and joomla try to find itemid, so donĀ“t find the view and show the default view in the modal.
So I change the name of file without camelCase and now work.!
I'm wanting to display images. The user can add up to 7 images, but they can also add less than 7 if needed.
I searched around and saw that file_exists() is the function I'm after, but I've tried a couple of ways and it always gives me no image.
Here's one way I tried:
<?php if(file_exists(base_url() . "photos/" . $p['p_id'] . "_5.jpg")):?>
<div class="single">
<a href="<?php echo base_url();?>photos/<?php echo $p['p_id'];?>_5.jpg" rel="lightbox[image]">
<img src="<?php echo base_url();?>photos/<?php echo $p['p_id'];?>_5.jpg" style="width:100px; height:100px;"/>
</a>
</div>
<?php endif; ?>
Then I searched around and found out that its not a good idea to define the path inside the function, so I defined it outside:
<?php $path = base_url() . "photos/" . $p['p_id'] . "_";?>
<?php $img4 = $path . "4.jpg";?>
<?php if(file_exists($img4)):?>
which didn't work either.I'm testing with 4 images being in the folder 'photos' so I know there should be 4 images being displayed. Any ideas on how I should fix it would be great. Thanks
The function file_exists accepts file path as its parameter and not the url like what you're using now which is CodeIgniter's base_url().
You should use the FCPATH constant which points to your codeigniter app's base directory.
This is what you should assign to your path (depending on where your image files are located in your application directory):
<?php $path = FCPATH . "htdocs/images/" . $product[0]['product_id'] . "_";?>
But for some reason if really you need to use the base_url(). You can use get_headers() which checks the headers returned by the url in an associative array and false on failure. From the headers returned you can determine whether the image url is valid or not. More about get_headers().
Hope it helps.
Cheers,
Ardy
File exists requires a directory path not a URL, a URL will always return false.
<?php
for($i=1; $i < 7; $i++):
{
$img = $path . $i . ".jpg";
$url=getimagesize($img);
if(!is_array($url))
{
?>
<div class="single">
<a href="<?php echo base_url();?>images/<?php echo $product[0]['product_id'];?>_<?php echo $i; ?>.jpg" rel="lightbox[productimage]">
<img src="<?php echo base_url();?>images/<?php echo $product[0]['product_id'];?>_<?php echo $i; ?>.jpg" style="width:100px; height:100px;"/>
</a>
</div>
<?php
}
}
?>
Be forewarned this is a touch on the slow side, but it does work with URL's on the server.
I have some of wiredness going on in some code I am writing. I have a regular form to update a user account. The fields are populated with data from the database. after changing that needs to be changed, I can't submit the form. when I click on the button, it behaves like disabled submit with javascript but I didn't. On the otherhand if I use javascript and stop it from submitting and console log to see if a click is happening, it appears the button is being clicked but just nothing. below is my code in my view for the form.
form_open('members/users/update_curr_user');
$data5 = array('name'=>'username','id'=>'username','value'=>$uservar['username']);
echo 'Username :'.form_input($data5);
$data6 = array('name'=>'email','id'=>'email','value'=>$uservar['email']);
echo 'Email Address :'.form_input($data6);
$phone1 = array('name'=>'phone','id'=>'phone','value'=>$uservar['phone']);
echo 'Your phone number formatted like so: 0802-331-5544'.form_input($phone1);
switch ($uservar['active']):
case 0:
$data7 = array(
'name'=>'status',
'id'=> 'status',
'value' =>'Deactivated'
);
echo 'Status : Active or Deactivated'.form_input($data7);
break;
case 1:
$data8 = array(
'name' =>'status',
'id' =>'status',
'value'=>'active'
);
echo 'Status :Active or Deactivated'.form_input($data8);
break;
endswitch;
$group1 = array('name'=>'group','id'=>'group','value'=>$uservar['group']);
echo 'Group :'.form_dropdown('group',$groups).'<br />';
echo '<br /><br />';
//$data9 = 'id="updateuser"';
//echo form_submit('submit','Update User',$data9);
?>
<input name="submit" id="updateuser" type="submit" value="Update User" />
<?php echo form_close();?>
Because of how unsure I was of what was going on I manually created a button still the same. Other forms on the page are working ok. If it's of any consequence, I am using phil sturgeon's template library, ion_auth and firephp.
You're not actually writing out the form tag. You need to put an echo up there. Do this:
echo form_open('members/users/update_curr_user');
Your submit button should now work.