I want to get the picture in the resume PDF or make a copy of it. I already tried some code from the internet but it is not working or the image must have effect like shadow or glow to work, I need a PHP code that can get image/Picture. For example, when i upload resume PDF, I want to get the 2x2 picture from it or make a copy of it.
These is the code that I already tried but it only works when the images have effects.
require_once('lib/nusoap.php');
class extractImagesFromPdf {
public function toByteArray($file01)
{
if (!($fp = fopen($file01, "r")))
die ("can not open file: " . $file01) ;
$file = file_get_contents($file01);
$byteArr = str_split($file);
$length = sizeof($byteArr) ;
$data = "" ;
for($i = 0; $i < $length; $i++) {
$data .= base64_encode($byteArr[$i]);
}
return $data ;
}
function main ($subSerial, $fileContent)
{
$client = new nusoap_client("http://www.biclim.com/WS/BCService?wsdl", true);
$params[] = array('subSerial' => $subSerial,
'fileContent' => $fileContent
);
$result = $client->call("extractImagesFromPdf", $params);
$images = $result["extractImagesFromPdfResponse"];
print_r($images);
$i = 0;
$theDate = date("dmY_His") ;
foreach($images AS $image) {
$fp = fopen('d:/fileImages_Page' . $image['pageNumber'] . "_image" . $i . "_" . $theDate . "." . $image['imageType'], 'w');
print "\nExtracting Image " . $i . " in Page :" . $image['pageNumber'] ;
fwrite($fp, base64_decode($image['content']));
fclose ($fp);
$i = $i + 1;
}
}
}
$subSerial = "DEMO";
$extractImagesFromPdf = new extractImagesFromPdf() ;
$fileContent = $extractImagesFromPdf->toByteArray("D:/2.pdf") ;
$extractImagesFromPdf->main($subSerial, $fileContent);
Related
I have this issue on one of servers, Up until last week, the feed it was pulling the content from was working fine. Now suddenly since last few days, when I made the change to extract category field from database since then it is not extracting the image from the feed but is able to extract all of other content. (This server was set up by previous developer).
I keep getting this error:
going to get file 2020-07-23T15:41:05
going to put /var/www/SpanishMix/
!! problem getting remote file ( 2020-07-23T15:41:05 ) in checkNGet ** trying replace , digiv/2105318.jpg
This is the code in php file:
<?php
set_time_limit(90);
ini_set('memory_limit', '128M');
$xurl = 'feedlink.com/feed/getXML.php';
$locs = 'server ip';
$locvid = '/var/www/SpanishMix/';
function decrypto($inStr)
{
$key = '';
$encrypted = $inStr;
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
return $decrypted;
}
function dis($v)
{
echo "<pre>\n";
print_r($v);
echo "\n</pre>\n<hr>\n";
}
// --------------------- grab XML
$c = file_get_contents($xurl);
if (strlen($c) < 100) {
exit('couldnt get data from CMS');
}
// --------------------- parse into usable array of objects
$sa = array();
$ta1 = explode('_ENDI_', $c);
foreach ($ta1 as $i) {
$ta2 = explode('_ENDF_', $i);
if ((strlen($ta2[0]) > 4) && (strlen($i) > 200)) {
$to = new stdClass();
$to->uid = $ta2[0];
$to->vurl = "";
$to->body = $ta2[1];
$to->people = trim($ta2[2]);
$to->headline = trim($ta2[3]);
$to->category = trim($ta2[4]);
$to->abstract = trim($ta2[5]);
$to->pubdate = trim($ta2[7]);
$to->storyid = trim($ta2[6]);
$to->iurl = trim($ta2[8]);
$tmpia = explode('.com/', $to->iurl);
$to->cpi = $tmpia[1];
$to->iloc = 'http://' . $locs . '/SpanishMix/' . $tmpia[1];
// code for durability date
$tmpda = explode('-', $to->pubdate);
$oldy = $tmpda[0];
$newy = $oldy + 1;
$newys = str_replace($oldy, $newy, $to->pubdate);
$to->durdate = $newys;
$to->gotv = 0;
$to->fs = 0;
if ($to->uid > 10000) {
$sa[$to->uid] = $to;
}
}
}
dis($sa);
// --------------------- scan vids dir, parse into array including filesize
$va = array();
$dir = $locvid . "*.jpg";
foreach (glob($dir) as $file) {
$tv = new stdClass();
$tv->fn = $file;
$tv->s = filesize($file);
array_push($va, $tv);
}
dis($va);
// --------------------- check through stories array structure marking those already with video
$vtg = '';
$itg = '';
$uidtg = '';
// loop through each story
foreach ($sa as $s) {
$found = 0;
foreach ($va as $v) {
// hack out matchable filename from video and story arrays
$tfn = '/var/www/SpanishMix/' . $s->cpi;
if ($tfn == $v->fn) {
$found = 1;
}
}
// if outer looop variable says no video found for this story, make this storey's video URL next to get
if (!$found) {
echo "<br>setting itg to $s->iurl<br>\n";
$itg = $s->iurl;
$uidtg = $s->uid;
}
}
echo "<hr><h1> getting video part</h1><br><br>";
// --------------------- elect first story entry with no file
if ($itg) {
// split img url to take
$ifa = explode('.com/', $itg);
$itg = $itg;
$outfile = '/var/www/SpanishMix/' . $ifa[1];
echo "\n<br><b>going to get file $itg<br>going to put $outfile</b><br>\n";
$remoteFile = file_get_contents($itg);
if (!$remoteFile) {
echo "!! problem getting remote file ( $itg ) in checkNGet\n\n";
} else {
$res = file_put_contents($outfile, $remoteFile);
if ($res) {
echo "put remote image file ( $outfile ) success !\n\n\n";
// NOW COPY LOCAL FILE TO FUNNY FILENAME
$cpifn = '/var/www/SpanishMix/digiv/' . $uidtg . '.jpg';
echo "* about to copy $outfile to $cpifn\n\n";
copy($outfile, $cpifn);
} else {
echo "put remote image file ( $outfile ) fail :( \n\n\n<br><br>";
}
}
}
$tt = '';
$tm = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<videonews>
<news>
<name>BBCC**storyid**</name>
<title>**headline**</title>
<subtitle>**abstract**</subtitle>
<text>**body**</text>
<keywords>**people**</keywords>
<date>**pubdate**</date>
<durability>**durdate**</durability>
<category>**category**</category>
<subcategory>Famosos</subcategory>
<image>
<file format="image">**iloc**</file>
</image>
</news>
</videonews>
';
$tb = '';
$out = $tt;
foreach ($sa as $s) {
if ($s->uid == $uidtg) {
$tfn = "$locs/SpanishMix/" . $tfna[3];
$tmpt = str_replace('**body**', $s->body, $tm);
//$tmpt = str_replace('**vidfs**', $s->fs, $tmpt);
$tmpt = str_replace('**headline**', $s->headline, $tmpt);
$tmpt = str_replace('**people**', $s->people, $tmpt);
$tmpt = str_replace('**abstract**', $s->abstract, $tmpt);
$tmpt = str_replace('**storyid**', $s->storyid, $tmpt);
$tmpt = str_replace('**category**', $s->category, $tmpt);
$tmpt = str_replace('**pubdate**', $s->pubdate, $tmpt);
$tmpt = str_replace('**durdate**', $s->durdate, $tmpt);
$tmpt = str_replace('**iloc**', $s->iloc, $tmpt);
$copyA2 = explode('SpanishMix/', $s->iloc);
$copyImageFN = $copyA2[1];
$copyNewImageFN = 'digiv/' . $uidtg . '.jpg';
echo "\n ** trying replace $copyImageFN, $copyNewImageFN\n";
$tmpt = str_replace($copyImageFN, $copyNewImageFN, $tmpt);
$out .= "$tmpt\n\n";
}
}
$out .= $tb;
if ($uidtg) {
echo "</pre><TEXTAREA cols='120' rows='80'>$out</TEXTAREA>\n";
echo "<hr>";
$ox = '/var/www/SpanishMix/digiv/' . $uidtg . '.xml';
$written = file_put_contents($ox, $out);
echo "\nALSO putting : xml to $ox [", $written, "]<br>\n";
} else {
echo "\n NO UIDTG [", $uidtg, "] ! \n not putting any files";
}
I would really appreciate some help on this.
I am getting undefined offset. Please help, I can't find where's the problem at all :(
<?php
$fileTitle = $_GET['title'];
$rawData = $_GET['data'];
//fileTitle is testing
//rawData is 5000013,0.00,0.00,50.00,0+5006529,0.00,0.00,50.00,0
$lineData = explode("+",$rawData)
for( $i=0 ; $i<count($lineData) ; $i++)
{
$txtFileTitle = $fileTitle.".txt";
$txtFileLineData = $lineData[$i]."\r\n";
$txtFileStatus = file_put_contents($txtFileTitle, $txtFileLineData, FILE_APPEND);
if($txtFileStatus != false)
{
echo "SUCCESS: data written to txt file";
}
else
{
echo "FAIL: could not write to txt file";
}
}?>
The result is a .txt file with:
5000013,0.00,0.00,50.00,0+5006529,0.00,0.00,50.00,0
What i want is a .txt with:
5000013,0.00,0.00,50.00,0
5006529,0.00,0.00,50.00,0
I think the issue was due to the <= in the loop - as the counter begins at zero it would exceed the actual count by one and thus create the undefined index error.
<?php
$title = $_GET['title'];
$data = $_GET['data'];
//title is testing
//data is 5000013,0.00,0.00,50.00,0+5006529,0.00,0.00,50.00,0
$lines = explode( "+", $data );
$file = $title . ".txt";
for( $i=0 ; $i < count( $lines ); $i++ ){
$content = $lines[ $i ] . PHP_EOL;
$status = file_put_contents( $file, $content, FILE_APPEND );
echo $status ? 'SUCCESS: data written to txt file' : 'FAIL: could not write to txt file';
}
?>
edit
The use of + in the source data is ambiguous because the + is used in urls when they are encoded ( space )
<?php
$title = $_GET['title'];
$data = urlencode( $_GET['data'] );
$lines = explode( "+", $data );
$file = __DIR__ . '/' . $title . ".txt";
for( $i=0 ; $i < count( $lines ); $i++ ){
$content = urldecode( $lines[ $i ] ) . PHP_EOL;
$status = file_put_contents( $file, $content, FILE_APPEND );
echo $status ? 'SUCCESS: data written to txt file' : 'FAIL: could not write to txt file';
}
?>
You can simple to use preg_replace function to replace + whith space
$fileTitle = $_GET['title'];
$rawData = $_GET['data'];
$txtFileLineData = preg_replace('/\+/', ' ', $rawData);
$txtFileTitle = $fileTitle.".txt";
$txtFileStatus = file_put_contents($txtFileTitle, $txtFileLineData, FILE_APPEND);
if ($txtFileStatus != false) {
echo "SUCCESS: data written to txt file";
} else {
echo "FAIL: could not write to txt file";
}
i try with for loop,while loop, recursion...
nothing help.
maybe some pointers or memory-limit problems?
please help me :(
my code:
/*$arrImg = [['name'=>'some name', 'note'=> 'some url-image from ajax'],
['name'=>'some other name', 'note'=> 'some other url-image from
ajax']],...];*/
function saveMyImageFromString($string, $filename) {
$data = imagecreatefromstring(base64_decode(str_replace(' ', '+', $string)));
imagealphablending($data, false);
imagesavealpha($data, true);
imagepng($data, $filename);
imagedestroy($data);
unset($data);
}
$directory = 'img/';
$filename = 'deleteme.png';
$len = count($arrImg);
$iterationHeight = 0;
for ($i = 0; $i < $len; $i++) {
saveMyImageFromString($arrImg[$i]['note'], $directory . $i . $filename);
}
function printAll($dirName)
{
if (empty($leid)) { $leid = "1"; }
$root = $_SERVER['DOCUMENT_ROOT'];
$site = $_GET['site'];
$user = $_GET['user'];
$tag = "";
$dirs=array($dirName);
$files=array();
while($dir=array_pop($dirs)){
$handle=opendir($dir);
while($file=readdir($handle)){
if($file!='.' && $file!='..'){
$dest=$dir.'/'.$file;
$userid = str_replace("$root/", "", $dir);
$userid = str_replace("dl/$site","",$userid);
$userid = str_replace("/","",$userid);
if(is_file($dest)){
$files[]=$file;
$titrepost = htmlspecialchars($file);
$downloadlink = "$dest";
$downloadlink = str_replace("$root/", "", $downloadlink);
$za = new ZipArchive();
$za->open($downloadlink);
$leid = $leid + 1;
echo "<br>
<b>File = $file</b><br>
Userid = $userid
<br>";
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$toune = basename( $stat['name'] );
echo "$toune <br>";
}
} else {
$dirs[]=$dest;
}
}
}
}
return $files;
}
$site = $_GET['site'];
$currentdir = getcwd();
$source = "$currentdir/dl/$site";
if (!empty($user)) {
$source = "$currentdir/dl/$site/$user";
}
printAll($source);
This script will list all files inside a ZIP archive then echo the name of each files.
Now i'm having some trouble figuring how to sort the files names ($toune) alphabetically
Here's what i tried:
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$toune_arr[] = basename( $stat['name'] );
}
asort($toune_arr);
print_r($toune_arr);
But it doesn't work for this code, $toune_arr won't empty after each zip file is listed so each time the script output the filelist it contains the files of the previous zip archives.
Just reset your array in the begining of your function:
function printAll($dirName)
{
$toune_arr = array();
...
I want to export a row in CSV file to JSON file with require : 1 line in CSV export 1 file JSON. I success to export file,but can't filter the row that i want to export. Can anyone help me?
<?php
header('Content-type: application/json');
$feed = 'jsondata_palpad.csv';
$keys = array();
$newArray = array();
function csvToArray($file, $delimiter) {
if (($handle = fopen($file, 'r')) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter, '"')) !== FALSE) {
for ($j = 0; $j < count($lineArray); $j++) {
$arr[$i][$j] = $lineArray[$j];
}
$i++;
}
fclose($handle);
}
return $arr;
}
$data = csvToArray($feed, ',');
$count = count($data) - 1;
$labels = array_shift($data);
foreach ($labels as $label) {
$keys[] = $label;
}
$keys[] = 'id';
for ($i = 0; $i < $count; $i++) {
$data[$i][] = $i;
}
for ($j = 0; $j < $count; $j++) {
$d = array_combine($keys, $data[$j]);
$newArray[$j] = $d;
}
//Xuat file JSON
for ($i = 0; $i < 5; $i++) {
$json = json_encode($newArray[$i]);
echo $json . "<br />\n";
$filename = $data[$i][1] . ".json";
echo $filename . "<br />\n";
//echo "title[" . $data[$i][4] . "]";
$handle = fopen("./" . $filename, "w");
fwrite($handle, $json);
fclose($handle);
}
?>
If recommend = 2,it will export line whre id=2.
I want to export id,product_id,title,outline to JSON file.This is sample JSON file:
http://img839.imageshack.us/img839/5277/21527799.png
This is CSV file :
http://img690.imageshack.us/img690/1526/43004273.png
You are looping through all 6 lines of the csv file and saving them to the JSON file:
for ($i = 0; $i < 5; $i++) {
...
}
If you know what row number it is you want, don't loop through every row - just call the code inside the loop for that row. For example, if you wanted the 2nd row:
$row_we_want = 1;
$json = json_encode($newArray[$row_we_want]);
$filename = $data[$row_we_want][1] . ".json";
$handle = fopen("./" . $filename, "w");
fwrite($handle, $json);
fclose($handle);
If you are unsure about which row it is and need to check each one, you could do so in the loop:
for ($i = 0; $i < 5; $i++) {
if (some_condition) {
$json = json_encode($newArray[$i]);
$filename = $i][1] . ".json";
$handle = fopen("./" . $filename, "w");
fwrite($handle, $json);
fclose($handle);
}
}
Also it might be worth replacing 5 in your loop with the length of the array using the count function if it is not always a fixed length.