i have a module Drupal 7 to convert all page PDF to array Images then insert into my database, but it don't work
my file mymodule.module
<?php
/**
* @file
* TODO: Enter file description here.
*/
function vgs_system_skinr_api_2() {
return array(
'directory' => 'skins',
);
}
/**
* Implements hook_block_info().
*/
function vgs_system_menu() {
$items['contact'] = array(
'page callback' => 'vgs_system_contact',
'title' => '',
'description' => 'administration',
'type' => MENU_SUGGESTED_ITEM,
'access callback' => TRUE
);
$items['inscription'] = array(
'page callback' => 'vgs_system_contact',
'title' => 'Inscription',
'description' => 'formulaire',
'type' => MENU_SUGGESTED_ITEM,
'access callback' => TRUE
);
$items['informations'] = array(
'page callback' => 'vgs_system_contact',
'title' => 'Informations',
'description' => 'vos questions',
'type' => MENU_SUGGESTED_ITEM,
'access callback' => TRUE
);
$items['news'] = array(
'page callback' => 'vgs_system_contact',
'title' => 'News',
'description' => 'l\'actualité',
'type' => MENU_SUGGESTED_ITEM,
'access callback' => TRUE
);
$items['flipbook/%/print'] = array(
'title' => 'Print',
'description' => 'Print',
'page callback'=>'vgs_system_print',
'page arguments'=>array(1),
'type' => MENU_SUGGESTED_ITEM,
'access callback' => TRUE
);
$items['ajax/sendtofriend'] = array(
'title' => t('Ajax Send to friend'),
'page callback' => 'vgs_system_send_to_friend',
'access callback'=>TRUE,
);
return $items;
}
function vgs_system_send_to_friend(){
$subject ='';
$body ='';
$m1 = $_POST['yourname']. ' send link:';
$m1 .= $_POST['url'];
$subject = '[Flipbook] Send Link';
$body = $m1;
vietgest_sendmail_with_subject_body($_POST['yourfriendemail'],$subject,$body);
}
function vietgest_sendmail_with_subject_body($to,$subject,$body) {
$module = 'vgs_system';
$key = 'send_mail_subject_body';
$from = variable_get('site_mail', 'linhnc@vietgest.com');
$params = array('subject'=>$subject,'body'=>$body);
$language = language_default();
$send = TRUE;
$result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
return $result['result'];
}
function vgs_system_print($nid){
$node = node_load($nid);
echo '<style type="text/css" media="print">
@media print {
.button-pint{
display:none
}
}
</style>';
echo '<div class="header">';
echo '<div class="print"><a class="button-pint" href="javascript:window.print();"><img style="margin:0px 0px 10px;" src="'.base_path().'themes/garland/images/print.png" width="28" height="28" /></a></div>';
if($node->field_type_file['und'][0]['value'] == 1){
echo "<div class='image-print' style='height:800px'>";
foreach($node->field_image['und'] as $k => $v){
$image_src =file_create_url($v['uri']);
echo "<img src='".$image_src."' alt='' style='width: 481px; height: 620px;' />";
}
}else if($node->field_type_file['und'][0]['value'] == 2){
$query = db_select('convert_file_name', 'n');
$arguments = array(':nid' => $nid);
$query->fields('n',array('file_name_convert'));
$query->where('nid = :nid',$arguments);
$result = $query->execute();
echo "<div class='image-print' style='height:800px'>";
while($record = $result->fetchAssoc()) {
$file_name = unserialize($record['file_name_convert']);
foreach($file_name as $k=> $val_file_name){
echo "<img src='".base_path().'sites/default/files/convert/'.$val_file_name."' alt='' style='width: 100%; height: 100%;' />";
}
}
echo "</div>";
}else{
}
echo "</div>";
echo '</div>';
}
function vgs_system_contact(){
return '';
}
function vgs_system_preprocess_page(&$vars) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
switch (arg(2)) {
case 'edit':
$view_mode = 'nodeform';
break;
case 'delete':
return; // delete pages show you all information in title, we should not remove it
default:
$view_mode = 'full';
break;
}
//dpm($vars['node']->title);
//if ($vars['node']->title == 'Accueil' || $vars['node']->title == 'Historique') {
$vars['title'] = '';
//}
}
elseif (arg(0) == 'search' && variable_get('exclude_node_title_search', 0)) {
$vars['title'] = '';
}
//dpm($vars);
}
function vgs_system_node_view($node, $view_mode, $langcode) {
if($node->type == 'page' && $view_mode == 'full'){
$breadcrumb = array();
drupal_set_breadcrumb($breadcrumb);
}
//
// if($node->type == 'article' && $node->nid == 147){
//
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $breadcrumb[] = t('Sitemap');
// drupal_set_breadcrumb($breadcrumb);
// }
// if($node->type == 'page' && $node->path == 'sitemap'){
//
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $breadcrumb[] = t('Sitemap');
// drupal_set_breadcrumb($breadcrumb);
// }
// if ($node->type == 'article' && $view_mode == 'full') {
//
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
//
// if(count($node->field_types_de_articles)>0){
// $tid = $node->field_types_de_articles['und'][0]['tid'];
// if($tid>0){
// $term1 = taxonomy_term_load($tid);
// $parents = taxonomy_get_parents_all($tid);
// if(count($parents)>=2){
//
// $parents = array_reverse($parents);
// $first = $parents[0];
// $i=0;
// foreach($parents as $term){
// $result = db_select('menu_links','t')
// ->fields('t')
// ->condition('link_path', 'taxonomy/term/'.$term->tid,'=')
// ->condition('language', $langcode,'=')
// ->execute()
// ->fetchAssoc();
// if($i == count($parents) -1){
// $breadcrumb[] = $result['link_title'];
// }else{
// $breadcrumb[] = l($result['link_title'], 'taxonomy/term/'.$term->tid);
// }
// vgs_menu_active(url('taxonomy/term/'.$first->tid));
// $i++;
// }
// }
// }
// }else{
// $breadcrumb[] = drupal_get_title();
// }
//
// drupal_set_breadcrumb($breadcrumb);
//
//
// }
// unset($node->content['links']['translation']);
}
function vgs_system_views_pre_render(&$view) {
//if($view->name == 'article' && $view->current_display == 'page_2'){
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $tid = arg(2);
// $parents = taxonomy_get_parents_all($tid);
//
// $parents = array_reverse($parents);
// $first = $parents[0];
// $i=0;
// foreach($parents as $term){
// global $language;
// $l = $language->language;
// $result = db_select('menu_links','t')
// ->fields('t')
// ->condition('link_path', 'taxonomy/term/'.$term->tid,'=')
// ->condition('language', $l,'=')
// ->execute()
// ->fetchAssoc();
//
// if($i == count($parents) -1){
// $breadcrumb[] = $result['link_title'];
// }else{
// $breadcrumb[] = l($result['link_title'], 'taxonomy/term/'.$term->tid);
// }
// vgs_menu_active(url('taxonomy/term/'.$first->tid));
// $i++;
// }
// drupal_set_breadcrumb($breadcrumb);
// }
// if($view->name == 'article' && $view->current_display == 'page_3'){
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $breadcrumb[] = t('New news items');
// drupal_set_breadcrumb($breadcrumb);
// }
// if($view->name == 'article' && $view->current_display == 'page_4'){
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $breadcrumb[] = t('Article');
// drupal_set_breadcrumb($breadcrumb);
// }if($view->name == 'search'){
// $breadcrumb = array();
// $breadcrumb[] = l(t('Home'), '<front>');
// $breadcrumb[] = t('Search');
// drupal_set_breadcrumb($breadcrumb);
// }
}
function getNumPagesPdf($filepath){
$fp = @fopen(preg_replace("/\[(.*?)\]/i", "",$filepath),"r");
$max=0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('/\/Count [0-9]+/', $line, $matches)){
preg_match('/[0-9]+/',$matches[0], $matches2);
if ($max<$matches2[0]) $max=$matches2[0];
}
}
fclose($fp);
if($max==0){
$im = new imagick($filepath);
$max=$im->getNumberImages();
}
return $max;
}
function vgs_system_node_insert($node) {
if($node->type == 'page'){
drupal_goto('editor/pages');
}
if($node->type == 'profiles'){
drupal_goto('editor/profiles');
}
if($node->type == 'document'){
if(1){
require_once('saaspose.php');
//App SID
$AppSID = "";
//App Key
$AppKey = "";
//Base Product URI
$BaseProductUri = "http://api.aspose.com/v1.1";
if(isset($_REQUEST['AppSID']) == 1 && isset($_REQUEST['AppKey']) == 1)
{
$AppSID = $_REQUEST['AppSID'];
$AppKey = $_REQUEST['AppKey'];
}
//web server location to save file
$OutPutLocation = realpath("") . "/sites/default/files/convert/";
if ($_FILES["files"]["error"]["field_document_und_0"] > 0)
{
echo "Return Code: " . $_FILES["files"]["error"]["field_document_und_0"] . "<br />";
}
else
{
move_uploaded_file($_FILES["files"]["tmp_name"]["field_document_und_0"],realpath("") . "/sites/default/files/documents/" . $_FILES["files"]["name"]["field_document_und_0"]);
}
$file = $_FILES["files"]["name"]["field_document_und_0"];
UploadFile( realpath("") . "/sites/default/files/documents/" . $file, "", $BaseProductUri . "/storage/file/");
$A = getNumPagesPdf(realpath("") . "/sites/default/files/documents/" . $file);
//build URI
$i = 0;
$file_name_convert = array();
for($i = 1;$i <= $A ; $i++){
$strURI = $BaseProductUri . "/pdf/" . $file . "/pages/" . $i . "?format=" . $_REQUEST["ImageFormat"];
$file_name_convert[] = getFileName($file). "_" . $i . "." . $_REQUEST["ImageFormat"];
//sign URI
$signedURI = Sign($strURI);
$responseStream = processCommand($signedURI, "GET", "", "");
$v_output = ValidateOutput($responseStream);
if ($v_output === "")
{
saveFile($responseStream, $OutPutLocation . getFileName($file). "_" . $i . "." . $_REQUEST["ImageFormat"]);
//header('Location:download.php?file='. $OutPutLocation . getFileName($file). "_" . $_REQUEST["pageno"] . "." . $_REQUEST["ImageFormat"]);
}
else
echo $result;
}
db_insert('convert_file_name')
->fields(array('nid', 'file_name_convert'))
->values(array(
'nid' => $node->nid,
'file_name_convert' => serialize($file_name_convert),
))
->execute();
}
}
}
function vgs_system_node_update($node) {
if($node->type == 'page'){
drupal_goto('editor/pages');
}
if($node->type == 'profiles'){
drupal_goto('editor/profiles');
}
/*
if($node->type == 'document'){
if($_REQUEST['field_type_file']['und'] == 2){
require_once('saaspose.php');
//App SID
$AppSID = "";
//App Key
$AppKey = "";
//Base Product URI
$BaseProductUri = "http://api.saaspose.com/v1.0";
if(isset($_REQUEST['AppSID']) == 1 && isset($_REQUEST['AppKey']) == 1)
{
$AppSID = $_REQUEST['AppSID'];
$AppKey = $_REQUEST['AppKey'];
}
//web server location to save file
$OutPutLocation = realpath("") . "/sites/default/files/convert/";
if ($_FILES["files"]["error"]["field_document_und_0"] > 0)
{
echo "Return Code: " . $_FILES["files"]["error"]["field_document_und_0"] . "<br />";
}
else
{
move_uploaded_file($_FILES["files"]["tmp_name"]["field_document_und_0"],realpath("") . "/sites/default/files/documents/" . $_FILES["files"]["name"]["field_document_und_0"]);
}
$file = $_FILES["files"]["name"]["field_document_und_0"];
UploadFile( realpath("") . "/sites/default/files/documents/" . $file, "", $BaseProductUri . "/storage/file/");
$A = getNumPagesPdf(realpath("") . "/sites/default/files/documents/" . $file);
//build URI
$i = 0;
$file_name_convert = array();
for($i = 1;$i <= $A ; $i++){
$strURI = $BaseProductUri . "/pdf/" . $file . "/pages/" . $i . "?format=" . $_REQUEST["ImageFormat"];
$file_name_convert[] = getFileName($file). "_" . $i . "." . $_REQUEST["ImageFormat"];
//sign URI
$signedURI = Sign($strURI);
$responseStream = processCommand($signedURI, "GET", "", "");
$v_output = ValidateOutput($responseStream);
if ($v_output === "")
{
saveFile($responseStream, $OutPutLocation . getFileName($file). "_" . $i . "." . $_REQUEST["ImageFormat"]);
//header('Location:download.php?file='. $OutPutLocation . getFileName($file). "_" . $_REQUEST["pageno"] . "." . $_REQUEST["ImageFormat"]);
}
else
echo $result;
}
db_insert('convert_file_name')
->fields(array('nid', 'file_name_convert'))
->values(array(
'nid' => $node->nid,
'file_name_convert' => serialize($file_name_convert),
))
->execute();
}
}
*/
}
function vgs_system_init(){
drupal_add_js( array( 'vgs_system' => array( 'base_path' => base_path() )), 'setting' );
drupal_add_library('system', 'ui.draggable');
variable_set('shortcut_max_slots', 10);
}
function vgs_system_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'system_site_information_settings'){
$form['site_information']['site_slogan']['#type'] = 'textarea';
}
}
function vgs_system_contact_node_form_submit($form, &$form_state){
// global $language;
// $body = "\n".'Prénom: '.$form_state['values']['submitted_tree']['votre_prenom'].
// "\n".'Votre nom: '.$form_state['values']['submitted_tree']['votre_nom'].
// "\n".'Votre e-mail : '.$form_state['values']['submitted_tree']['votre_e_mail'].
// "\n".'Sujet de message : '.$form_state['values']['submitted_tree']['sujet_de_message'].
// "\n".'Votre message : '.$form_state['values']['submitted_tree']['votre_message'].
// $to = variable_get('site_mail', 'contact@itsense.fr');
// $params['subject'] = $form_state['values']['submitted_tree']['sujet_de_message'];
// $params['body'] = $body;
//
// $from = $form_state['values']['submitted_tree']['votre_e_mail'];
// drupal_mail('vg_itsense', 'contact', $to, language_default(),$params, $from, TRUE);
//
// drupal_set_message(t('Merci de nous contacter!'));
// drupal_goto('<front>');
}
function vgs_system_mail($key, &$message, $params) {
if ($key == 'send_mail_subject_body') {
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
}
}
function vgs_system_contact_node_form_validate($form, &$form_state)
{
// if ($form_state['values']['submitted_tree']['votre_e_mail'] && !valid_email_address($form_state['values']['submitted_tree']['votre_e_mail'])) {
// form_set_error('email', t('La condition de l\'e-mail n\'est pas valide.'));
// }
}
function vgs_system_theme($existing, $type, $theme, $path)
{
$themes = array(
'document_node_form' => array(
'arguments' => array('form' => null),
'template' => 'document-node-form',
),
);
return array(
'document_node_form' => array(
'render element' => 'form',
'template' => 'document-node-form',
'path' => drupal_get_path('module', 'vgs_system'),
),
);
}
and my saaspose.php
<?php
/**
* Performs Saaspose Api Request.
*
* @param string $url Target Saaspose API URL.
* @param string $method Method to access the API such as GET, POST, PUT and DELETE
* @param string $headerType XML or JSON
* @param string $src Post data.
*
*
*/
use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Utils;
use Aspose\Cloud\Common\Product;
use Aspose\Cloud\Pdf\Extractor;
function processCommand($url, $method="GET", $headerType="XML", $src="") {
$method = strtoupper($method);
$headerType = strtoupper($headerType);
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
if ($method == "GET") {
curl_setopt($session, CURLOPT_HTTPGET, 1);
}else {
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $src);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
}
curl_setopt($session, CURLOPT_HEADER, false);
if ($headerType == "XML") {
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
} else {
curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
}
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if (preg_match("/^(https)/i", $url))
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($session);
curl_close($session);
return $result;
}
/**
* Performs Saaspose Api Request to Upload a file.
*
* @param string $url Target Saaspose API URL.
* @param string $localfile Local file
* @param string $headerType XML or JSON
*
*
*/
function uploadFileBinary($url, $localfile, $headerType="XML") {
$headerType = strtoupper($headerType);
$fp = fopen($localfile, "r");
$session = curl_init();
curl_setopt($session, CURLOPT_VERBOSE, 1);
curl_setopt($session, CURLOPT_USERPWD, 'user:password');
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_PUT, 1);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($session, CURLOPT_HEADER, false);
if ($headerType == "XML") {
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
} else {
curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
}
curl_setopt($session, CURLOPT_INFILE, $fp);
curl_setopt($session, CURLOPT_INFILESIZE, filesize($localfile));
$result = curl_exec($session);
//$error = curl_error($session);
//$http_code = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session);
fclose($fp);
return $result;
}
/**
* Encode a string to URL-safe base64
*
* @param string $value Valure to endode.
*
*
*/
function encodeBase64UrlSafe($value) {
return str_replace(array('+', '/'), array('-', '_'), base64_encode($value));
}
/**
* Decode a string from URL-safe base64
*
* @param string $value Value to Decode.
*
*
*/
function decodeBase64UrlSafe($value) {
return base64_decode(str_replace(array('-', '_'), array('+', '/'), $value));
}
function Sign($UrlToSign) {
// parse the url
$url = parse_url($UrlToSign);
if (isset($url['query']) == "")
$urlPartToSign = $url['path'] . "?appSID=" . $_REQUEST['AppSID'];
else
$urlPartToSign = $url['path'] . "?" . $url["query"] . "&appSID=" . $_REQUEST['AppSID'];
// Decode the private key into its binary format
$decodedKey = decodeBase64UrlSafe($_REQUEST['AppKey']);
// Create a signature using the private key and the URL-encoded
// string using HMAC SHA1. This signature will be binary.
$signature = hash_hmac("sha1", $urlPartToSign, $decodedKey, true);
$encodedSignature = encodeBase64UrlSafe($signature);
if (isset($url['query']) == "")
return $url["scheme"] . "://" . $url["host"] . $url["path"] . "?appSID=" . $_REQUEST['AppSID'] . "&signature=" . $encodedSignature;
else
return $url["scheme"] . "://" . $url["host"] . $url["path"] . "?" . $url["query"] . "&appSID=" . $_REQUEST['AppSID'] . "&signature=" . $encodedSignature;
}
/**
* Will get the value of a field in JSON Response
*
* @param string $jsonRespose JSON Response string.
* @param string $fieldName Field to be found.
*
* @return getFieldValue($jsonRespose, $fieldName) - String Value of the given Field.
*/
function getFieldValue($jsonRespose, $fieldName) {
return json_decode($jsonResponse)->{$fieldName};
}
/**
* This method parses XML for a count of a particular field.
*
* @param string $jsonRespose JSON Response string.
* @param string $fieldName Field to be found.
*
* @return getFieldCount($jsonRespose, $fieldName) - String Value of the given Field.
*/
function getFieldCount($jsonResponse, $fieldName) {
$arr = json_decode($jsonResponse)->{$fieldName};
return count($arr,COUNT_RECURSIVE);
}
/**
* Copies the contents of input to output. Doesn't close either stream.
*
* @param string $input input stream.
*
* @return copyStream($input) - Outputs the converted input stream.
*/
function copyStream($input){
return stream_get_contents($input);
}
/**
* Saves the files
*
* @param string $input input stream.
* @param string $fileName fileName along with the full path.
*
*
*/
function saveFile($input, $fileName){
$fh = fopen($fileName, 'w') or die("can't open file");
fwrite($fh, $input);
fclose($fh);
}
/// <summary>
/// Uploads a file from your local machine to specified folder / subfolder on Saaspose storage.
/// </summary>
/// <param name="strFile"></param>
/// <param name="strFolder"></param>
function UploadFile($strFile, $strFolder, $strURIFile)
{
try
{
$strRemoteFileName = basename($strFile);
$strURIRequest = $strURIFile;
if($strFolder == "")
$strURIRequest .= $strRemoteFileName;
else
$strURIRequest .= $strFolder . "/". $strRemoteFileName;
$signedURI = Sign($strURIRequest);
uploadFileBinary($signedURI, $strFile);
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}
}
function getFileName($file)
{
$info = pathinfo($file);
$file_name = basename($file,'.'.$info['extension']);
return $file_name;
}
function ValidateOutput($result)
{
$string = (string)$result;
$validate = array("Unknown file format.", "Unable to read beyond the end of the stream",
"Index was out of range", "Cannot read that as a ZipFile", "Not a Microsoft PowerPoint 2007 presentation",
"Index was outside the bounds of the array", "An attempt was made to move the position before the beginning of the stream",
);
$invalid = 0;
foreach ($validate as $key => $value) {
$pos = strpos($string, $value);
if ($pos === 1)
{
$invalid = 1;
}
}
if($invalid == 1)
return $string;
else
return "";
}
?>
Pleasese help me
sorry for my english
Thanks!