Can someone here can help me on my problem ? I have this code on displaying output of pdf file on web using pdftotext
include ( 'PdfToText-master/PdfToText.phpclass' ) ;
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pdf_file" multiple="multiple">
<input type="submit" name="SubmitButton"/>
</form>
if(isset($_POST['SubmitButton'])){
$pdf = new PdfToText ($_FILES['pdf_file']['tmp_name']) ;
text = $pdf -> Text;
echo $text;
}
it works fine, But what im trying is to upload multiple files and display it on web all the files uploaded. I can't find any solution. Can you help me guys ? :(
PS: sorry my english is not that good. THank youuu!
where you upload multiple file. you will get the files in array.
Therefore, you need to loop over the tmp files
function show_pdf_text($file){
$pdf = new PdfToText ($file) ;
$text = $pdf->Text;
echo $text;
}
if(isset($_POST['SubmitButton'])){
if(is_array($_FILES['pdf_file']['tmp_name'])){
foreach($_FILES['pdf_file']['tmp_name'] as $temp){
show_pdf_text($temp);
}
}else show_pdf_text($_FILES['pdf_file']['tmp_name']);
}
Related
I am trying to generate PDF file in PHP wit DOMPDF, the variables will be passed from a <form>.
But something is wrong when viewing the PDF file.
If I hardcode the variables within same file, it works fine, but when I pass them from a <form> in a separate script file it shows that error.
Code:
<?php
require __DIR__ . "/vendor/autoload.php";
use Dompdf\Dompdf;
use Dompdf\options;
$staff = $_POST['staff'];
$asset = $_POST['asset'];
$serial = $_POST['serial'];
$description = $_POST['description'];
$designation = "ICT Assistant";
$mission = "Sudan Mission-Khartoum Office";
$crdate = date("d:m:Y");
$dompdf = new Dompdf (["chroot" =>__DIR__]);
$dompdf->setpaper("A4", "landscape");
$html = file_get_contents("aaf.html");
$html = str_replace(["{{name}}","{{designation}}","{{mission}}","{{date}}","{{asset}}"," {{description}}","{{serial}}"],[$staff,$designation,$mission,$crdate,$asset,$description,$serial],$html);
$dompdf->loadhtml($html);
$dompdf-> render();
$dompdf-> stream("Asset Form.pdf",["Attachment"=>0]);
?>
Trying to create a dynamin PDF using DOMPDF, I pass the variables from a <form>.
I have a form that receive info from the user, then I want to insert these info into a PDF file. My problem is when I run the code I receive following error message :error message and no PDF file generated.
below is the form code:
<Form action="tsets.php" method="post">
<input type="text" name="staff"><br>
<input type="text" name="asset"><br>
<input type="text" name="serial"><br>
<input type="text" name="description">
</Form>
Dear Cbros : thanks a lot for your replay , but I tried to download the file and open it with Adobe PDF but also the file is corrupted .
enter image description here
I want to post multiple images by posting the url's but I don't know how to do this because I am new to PHP.
<?PHP
if(isset($_POST['post_image']))
{
$image_url=$_POST['image_path'];
$data = file_get_contents($image_url);
$new = '../images/myimage.jpg';
$upload =file_put_contents($new, $data);
if($upload) {
echo "<img src='../images/myimage.jpg'>";
}else{
echo "Please upload only image files";
}
}
?>
The problem with your script is, that you are not saving the file anywhere. So you have no access to it when trying to return it to the client.
In order to save an image using a POST you need to make sure you have set the following enctype inside your form.
<form action="upload.php" method="post" enctype="multipart/form-data">
Then you can use this function to save the img
move_uploaded_file($_FILES["myImg"], "/path/to/imgDir")
And later show it to the client using:
echo "<img src='/path/to/imgDir/myImg'>"
For more information about the topic i advice you to consult the following URL
https://www.w3schools.com/php/php_file_upload.asp
i need your help please and i haven't found some answers for my problem.
I want to take a picture (or take it from the gallery) on the iphone/ipad and then encode the picture to a base64 string with php and send the base64 string to a webservice.
If i try it on the pc, everything is alright.
if i want to do this on the ipad, it seems like nothing or a incorrect base64 string is send to the webservice but i have no idea why or so?!
picture.php
<form action="picture.php?action=upload" method="post" enctype="multipart/form-data">
<input type="file" name="datei" accept="capture=camcorder">
<br/><br/>
<input type="submit" value="up">
</form>
<?
if(isset($_GET['action']))
{
$tmp_name = $_FILES["datei"]["tmp_name"];
$name = $_FILES["datei"]["name"];
$name = substr($name,0,-4);
$name.="_".time().".jpg";
move_uploaded_file($tmp_name, "upload/".$name);
$content = file_get_contents ( "upload/".$name );
$imageBase = base64_encode( $content );
$success = savePicture($imageBase);
}
function savePicture()
function savePicture($pic_base64)
{
ini_set("soap.wsdl_cache_enabled", "0");
$pageURL = 'http://....';
$page = new NTLMSoapClient($pageURL);
$params = array("pRecordID" => "1",
"pFieldID" => 70000,
"pUserID" => "153",
"pContent" => $pic_base64
);
$result = $page->SetBLOBValue($params);
if($result->return_value != "ERROR")
{
return true;
}
else
{
return false;
}
}
Any Ideas why this didn't work on ipad/iphone?
i hope anybody could help me.
I think that the iPhone/iPad has some problems with capture=camcorder.
Please try this:
<input type="file" name="datei" accept="image/*;capture=camera">
instead of
<input type="file" name="datei" accept="capture=camcorder">
For more information check this:
http://www.html5rocks.com/de/tutorials/getusermedia/intro/
SOLVED
The Problem is that the SOAP Service had a Max-Size for the Files for 1MB!
That was the Problem why i can't upload Base64 Strings who are bigger than 1MB!
Now we increase the Max-Size for Files to 10MB and now it works!
And that was the reason why i cant upload some pictures because some pictures was bigger than 1mb in the base64 string.
Thx for help to everybody!
I'm creating a website where users can uploads some images, URL images are saved into json and inserted into database so when I select all of the rows in the table it gives me something this.
{
"sroxrafm72pgipmpa4nz":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610510\/sroxrafm72pgipmpa4nz.jpg"
},
{
"egrrhg4umqgyjoltxrky":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610511\/egrrhg4umqgyjoltxrky.jpg"
},
{
"rfurg40o5af2h6s55thb":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610511\/rfurg40o5af2h6s55thb.jpg"
}
I need to decode it with twig to get the url of each id to display the images, but I just can't figure out to do this. I hope you guys can help me.
I'd say this is a clone of: Decoding JSON in Twig
What might be easier is to base64 encode the images and store the string inside of the database. I use the following:
In HTML:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="image" />
</form>
upload.php:
function getImageBase64($image_path) {
$image = imagecreatefromfile($image_path);
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
$image_string = 'data:image/png;base64,' . base64_encode($contents);
imagedestroy($image);
return $image_string;
}
if (getimagesize($_FILES["image"]["tmp_name"]) !== false) {
$image = getImageBase64($_FILES["image"]["tmp_name"]);
//Add to database...
}
I have two files, one to upload an image and another to retrieve it from the database and present it on the web page. However the image only appears as broken image icon. I do not understand why.
Thanks for any help in advance.
The HTML form:
<form action="index.php" method="POST" enctype="multipart/form-data">
<label for="image">File:</label>
<input type="file" name="image">
<input type="submit" value="Upload">
</form>
The php to upload it(The connection to the DB is left out below but it works perfectly):
//file stuff
$file= $_FILES['image']['tmp_name'];
if(!isset($file))
echo "Please select an image";
else {
$image=addslashes(file_get_contents($_FILES['image']['tmp_name']));
$imageName=addslashes($_FILES['image']['name']);
$imageSize=getimagesize($_FILES['image']['tmp_name']);
if(!$imageSize)
echo "Thats not an image you mong";
else {
//upload
$query="INSERT INTO store VALUES('','$imageName','$image')";
$sendQuery=mysql_query($query);
if(!$sendQuery)
echo "This is embarressing. It didn't work";
else {
$lastid=mysql_insert_id();
echo "Image was uploaded. <br>Your image:";
echo "<img src=get.php?id=$lastid/>";
}
}
}
The PHP to retrieve the image(Again the DB connection is left out below but works perfectly):
$id=addslashes($_REQUEST(['id']));
$imageQuery="SELECT * FROM store WHERE id=$id;";
$sendImageQuery=mysql_query($imageQuery);
$image=mysql_fetch_assoc($sendImageQuery);
$image=$image['image'];
header("Content-type: image/jpeg");
echo $image;
Make sure the the opening php tag is the very first line of the file. If the opening php tag is not on the first line of the file then content has already been written to the response causing calls to the header() function to be ignored.
<?php // this has to be on line 1
// do database connections stuff, no output can be sent to the response.
$id=addslashes($_REQUEST(['id']));
$imageQuery="SELECT * FROM store WHERE id=$id;";
$sendImageQuery=mysql_query($imageQuery);
$image=mysql_fetch_assoc($sendImageQuery);
$image=$image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
Maybe one of the magic quote setting (magic_quotes_gpc), try:
$image=stripslashes($image['image']);
You should be using mysql_real_escape_string() instead of addslashes() and only if magic quotes are not enabled.