image src is not displaying the page in php - image

**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 ^^

Related

How can i save data from HTML img tag in laravel

I have a form include image, this image i get from webcam and store it to img tag, how can i save data from attribute src, usually to store file using upload file.
<img id="myImage" src="data:image/png;base64,IvBo9Vraf...." alt="image from snapshot" />
I have read similar questions but not as i expected
With this code you can saved the files.
$filename = $request->file('myFile')->store('files');
$data= new FileModel();
$data->file = $filename;
$data->save();
or you can try below method
$myImage = $request->file('myFile');
if(!in_array($myImage->getMimeType(), ['image/jpeg', 'image/png'])){
abort(500, 'Unsupported Image Type');
}
$imageName = str_replace('myImages/', '', $myImage->store('myFile'));
return ['my_image'=>$profile_picture_name];

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();?>

Code for exif data of an 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

how to upload images without reloading page in modx revolution

How to upload images in web context (frontend) without reloading the page in modx revolution? I am trying to use fileupload extra for uploading images but it is reloading the page. Can anyone help me, please?
finally i got the answer. we can do it without using FILEUPLOAD addon by using the simple php code and a small javascript..
php code:-
<?php
$path = "uploads/";
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024)) // Image size max 1 MB
{
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
echo "image uploaded";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
for other javascript and all u can refer the below link:-
http://www.9lessons.info/2011/08/ajax-image-upload-without-refreshing.html

filename and contenttype of upload image

how to get the name of the file and the content type of the image which we uploaded in mvc application please tell me its urgent
thanks
ritz
May be below code will be helpful..
//index..
<?php
require_once("include/DBConnect.php");
include_once('header.php');
?>
<div align="center">
<h1 style="color:red">Welcome </h1>
<br/>
<form action="upload.php" method="post" enctype="multipart/form-data" id="UploadForm">
<input name="ImageFile" type="file" />
<input type="submit" id="SubmitButton" value="Upload" />
</form>
</div>
<?php include_once('footer.php');?>
//upload
<?php
require_once("include/DBConnect.php");
require_once("include/FunctionGeneral.php");
include_once('header.php');
if(isset($_POST))
{
$ThumbSquareSize = 200; //Thumbnail will be 200x200
$BigImageMaxSize = 500; //Image Maximum height or width
$ThumbPrefix = "thumb_"; //Normal thumb Prefix
$DestinationDirectory = 'uploads/'; //Upload Directory ends with / (slash)
$Quality = 90;
// check $_FILES['ImageFile'] array is not empty
if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name']))
{
die('Something went wrong with Upload!'); // output error .
}
// Random number for both file, will be added after image name
$RandomNumber = rand(0, 9999999999);
// Elements (values) of $_FILES['ImageFile'] array
//let's access these values by using their index position
$ImageName = str_replace(' ','-',strtolower($_FILES['ImageFile']['name']));
$ImageSize = $_FILES['ImageFile']['size']; // Obtain original image size
$TempSrc = $_FILES['ImageFile']['tmp_name']; // Tmp name of image file stored in PHP tmp folder
$ImageType = $_FILES['ImageFile']['type']; //Obtain file type, returns "image/png", image/jpeg, text/plain etc.
switch(strtolower($ImageType))
{
case 'image/png':
$CreatedImage = imagecreatefrompng($_FILES['ImageFile']['tmp_name']);
break;
case 'image/gif':
$CreatedImage = imagecreatefromgif($_FILES['ImageFile']['tmp_name']);
break;
case 'image/jpeg':
case 'image/pjpeg':
$CreatedImage = imagecreatefromjpeg($_FILES['ImageFile']['tmp_name']);
break;
default:
die('Unsupported File!'); //output error and exit
}
//PHP getimagesize() function returns height-width from image file stored in PHP tmp folder.
list($CurWidth,$CurHeight)=getimagesize($TempSrc);
//Get file extension from Image name, this will be re-added after random name
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);
//remove extension from filename
$ImageName = preg_replace("/\\.[^.\\s]{3,4}$/", "", $ImageName);
//Construct a new image name (with random number added) for our new image.
$NewImageName = $ImageName.'-'.$RandomNumber.'.'.$ImageExt;
//set the Destination Image
$thumb_DestRandImageName = $DestinationDirectory.'thumbnail/'.$ThumbPrefix.$NewImageName; //Thumb name
$DestRandImageName = $DestinationDirectory.$NewImageName; //Name for Big Image
//Resize image to our Specified Size by calling resizeImage function.
if(resizeImage($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType))
{
//Create a square Thumbnail right after, this time we are using cropImage() function
if(!cropImage($CurWidth,$CurHeight,$ThumbSquareSize,$thumb_DestRandImageName,$CreatedImage,$Quality,$ImageType))
{
echo 'Error Creating thumbnail';
}
/*
At this point we have succesfully resized and created thumbnail image
We can render image to user's browser or store information in the database
For demo, we are going to output results on browser.
*/
echo '<div id="output">';
echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">';
echo '<tr>';
echo '<td align="center"><img src="'.$thumb_DestRandImageName.'" alt="Thumbnail"></td>';
echo '</tr><tr>';
echo '<td align="center"><img src="'.$DestRandImageName.'" alt="Resized Image"></td>';
echo '</tr>';
echo '</table>';
echo '</div>';
/*
// Insert info into database table!
mysql_query("INSERT INTO myImageTable (ImageName, ThumbName, ImgPath)
VALUES ($DestRandImageName, $thumb_DestRandImageName, 'uploads/')");
*/
$added = getCurDate();
$title = "test";//$dbObj->escape_special_char($_POST['title']);
session_start();
$_SESSION['user_id'] = "rakhi";
$user_id = $_SESSION['user_id'];
$fields = "`photo_title` ,`createuser` ,`image_name` ,`added`";
$values = "'$title','$user_id','$NewImageName','$added'";
}else{
die('Resize Error'); //output error
}
}
include_once('footer.php');
?>

Resources