Code for exif data of an image - image

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

Related

image src is not displaying the page in php

**I'm trying to upload the img path in database and show them in the slider, but the problem is the img src is not showing the page assigned. Can any body tell me why the image src is not loading the page.
my code is below slider.php slider has this image code :<img src='<?php echo "imagetest.php?id=$id" ?> width="200"> the image path couldn't display the page imagetest.php has following code: this page is not showing up in img src of the slider if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
echo 'A valid image file id is required to display the image file.';
exit;
}
$imageId = $_GET['id'];
//connect to mysql database
if ($conn = mysqli_connect('localhost', 'root', 'root', 'test')) {
$content = mysqli_real_escape_string($conn, $content);
$sql = "SELECT type, content FROM images where id = {$imageId}";
if ($rs = mysqli_query($conn, $sql)) {
$imageData = mysqli_fetch_array($rs, MYSQLI_ASSOC);
mysqli_free_result($rs);
} else {
echo "Error: Could not get data from mysql database. Please try again.";
}
//close mysqli connection
mysqli_close($conn);
} else {
echo "Error: Could not connect to mysql database. Please try again.";
}
if (!empty($imageData)) {
// show the image.
header("Content-type: {$imageData['type']}");
echo $imageData['content'];
}
?>
Use file_get_contents
<img src="<?php echo file_get_contents('imagetest.php?id='. $id);?>" width="200"/>
and remove header(), u don't need it.
In php file
function track(){
header('Content-Type: image/gif');
$image = 'image.gif';
echo file_get_contents($image);
}
In view file
<img src="track.php" width="200"/>
Hope it's help ^^

Magento get the product image types (image, thumbnail, small_image)

I am retriving product details by id:
$model = Mage::getModel('catalog/product')->load($id);
I need to get product image details using below function:
$images = $model->getMediaGalleryImages();
But i am not getting the image type (image, thumbnail, small_image).
Can anyone please help me how to get this image types.
Thank You so much.
you can get image
$model = Mage::getModel('catalog/product')->load($id);
echo $model->getImage();
echo "<br>";
echo $model->getSmallImage();
echo "<br>";
echo $model->getThumbnail();
echo "<br>";
echo Mage::helper('catalog/image')->init($model, 'small_image')->resize(163,100); // resize function is used to resize image
echo "<br>";
echo Mage::helper('catalog/image')->init($model, 'image')->resize(400,400);
this will help you.
for thumbnail you can try this.
Mage::helper('catalog/image')->init($item->getProduct(), 'thumbnail');
for images:
Mage::helper('catalog/image')->init($_product, 'image')->resize(265);
for small images you can try this:
Mage::helper('catalog/image')->init($_product, 'small_image')->resize(163, 100);
I hope this will help you.

how to open pdf file to another tab in browser using codeigniter

im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code
controller:
function viewMinutesFile(){
if(isset($_GET['id'])){
$id = $_GET['id'];
$file = $this->minutes_model->getFile($id);
$fp= fopen($file->path, "r");
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file->filename."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' .filesize($file->path));
ob_clean();
flush();
while (!feof($fp)){
$buff = fread($fp,1024);
print $buff;
}
exit;
}
}
code to open the file: this is my syntax to be clicked by the user so that pdf file will be open in the new tab
File
index.php/admin/viewMinutesFile?
id=" target="_tab">
try this one with a static url. no need any extra words for that.
Show My Pdf
New Update
if its work for you then fetch pdf name from database and put the name in the view like
Show My Pdf
now in the controller
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
well, you could add a link to file with target="_blank", like
<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
View Pdf
</a>
and in controller function:
function viewMinutesFile(){
....
$file = $this->minutes_model->getFile($id);
$this->output
->set_content_type('application/pdf')
->set_output(file_get_contents($your_pdf_file));
}
you can try this on your view :
Filename
and on your controller, you can try this, because this is works for me :
function viewfile(){
$fname = $this->uri->segment(3);
$tofile= realpath("uploaddir/".$fname);
header('Content-Type: application/pdf');
readfile($tofile);
}
hope this might help you...
Just create a link to a blank page and use this code in your controller:
public function myPdfPage(){
$url = base_url('assets/your.pdf');
$html = '<iframe src="'.$url.'" style="border:none; width: 100%; height: 100%"></iframe>';
echo $html;
}
Enjoy!
There is no any problem with your code you can open easily on next tab, like other pages only difference you have to change header description and it is make sure on your browser pdf reader add-ons are available, otherwise it will give you option to download.
You may just follow this.
<?php echo form_open_multipart('your_controller/your_function','target="_blank"') ;?>
//other input fields
<?php form_close();?>

Image Upload in Cakephp

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">

CodeIgniter : image upload on article

I'm building a website with MongoDB and Codeigniter where users can create articles (title + text) and after it (but before to submit), upload some pictures (images are not in the text).
I think i will use jquery.upload for it. But my question is how to do link between pictures and article (because img will be uploaded first), how to rename them ?, is there any good way to do this ?
jquery upload would work. and check if it is success then create new hidden input into the form and set its value as you wish to use.
While I've never attempted this feature, this is a hypothetical solution that popped in my head:
Create a unique string on your Create Article page, and insert it into your document as a hidden field. A random string of 6 characters or something would probably be sufficient.
When uploading the images, use that string as an identifier for what future post the images belong to. Use the string in the file name, path, DB entry, or whatever's useful for your scenario.
When the article itself is submitted, the unique string will allow it to be identified with the images, and you can work whatever magic you need to at that stage to fully commit everything together.
Keep in mind that you should have some sort of statistics and/or garbage collection regarding any images that are uploaded and then the related article is abandoned.
Add 'thumbnail' field in your table 'articles_table' . I removed the unnessary parts for simpler need.We will only use 'title' and 'thumbnail' as field.
View | create.php
<?php echo form_open_multipart('articles/insert'); ?>
Title <br>
<?php echo form_input('title','','id="title_input"'); ?><br>
Thumbnail<br>
<input type="file" name="file" size="20" />
<?php echo form_submit('Submit',"Submit"); ?>
<?php echo form_close(); ?>
Controller | articles.php
function insert()
{
//$this->articles_model->insert();
$this->articles_model->save();
redirect('articles/index');
}
Model | articles_model.php
function save($id=0)
{
$title=$this->input->post('title');
//Set the config
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpg|png|PNG';
$config['max_size'] = '1100';
$config['max_width'] = '11024';
$config['max_height'] = '1768';
$config['overwrite'] = FALSE;
//Initialize
$this->upload->initialize($config);
//Upload file
if( ! $this->upload->do_upload("file"))
{
//echo the errors
echo $this->upload->display_errors();
}
//If the upload success
$thumbnail = $this->upload->file_name;
if($id<1)
{
$data=array(
'title'=>$title,
'thumbnail'=>$thumbnail
);
$this->db->insert('articles_table',$data);
}
}

Resources