miteshpandey
January 19th, 2008, 08:44 AM
I have the following php script:
$query_db_95 = "INSERT INTO `node_revisions` (`nid`, `vid`, `uid`, `title`, `body`, `teaser`, `log`, `timestamp`, `format`) VALUES
(451, 451, 1, 'Import model images', '<?php\r\n\r\n// Written by Victor Kane - victorkane at awebfactory dot com dot ar\r\n// *** This script affects your database\r\n//\r\n// Edits by Jeff Vogelsang - jeffvogelsang at pqa dot com\r\n\r\n// CONFIGURATION\r\n\r\n// Change the value below to TRUE when you want to run the script After running,\r\n// immediately change back to FALSE in order to prevent accidentally executing\r\n// this script twice.\r\n// NOTE: I find the best way to do this is to leave it false. When you are ready\r\n// to execute, set to this variable to true, and then click Preview. The script\r\n// will execute, but will not be saved with the value set to true. This prevents\r\n// accidentally saving the script with the value set to true. Also, it prevents\r\n// the unfortunate situation where the cron job runs while it''s set to true,\r\n// and you get double imports.\r\n$active = false;\r\n$process_folder = ''import'';\r\n\r\nset_time_limit (120);\r\n\r\n// Bootstrap Drupal\r\ninclude_once 'includes/bootstrap.inc';\r\ninclude_once('includes/common.inc');\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\n\r\n// Check for the script being enabled, and for appropriate permissions.\r\nif ($active) {\r\n insert_content($process_folder);\r\n} else {\r\n print 'Variable active is set to false.';\r\n}\r\n\r\nfunction insert_content ($process_folder) {\r\n $folders = scandir($process_folder); \r\n foreach($folders as $folder){\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n // Make sure it is a directory and not a file\r\n if (is_dir($folder_path) && $folder != '.' && $folder != '..') {\r\n print ''<ul><li>found directory: '' . $folder . ''</ul>'';\r\n // Check if there is a node for the model \r\n // The node''s title should be the model name which then is the same as the directory\r\n if($node = node_load(array(title => $folder))){\r\n insert_images($process_folder,$folder, $node);\r\n }\r\n }\r\n }\r\n}\r\n \r\nfunction insert_images ($process_folder, $folder, $node) {\r\n $output = ''<ul>'';\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n if ($handle = opendir($folder_path)) {\r\n\r\n // Set the destination directory\r\n $dest = _node_images_get_directory($node);\r\n\r\n // Create the destination folders\r\n $directories = explode('/', $dest);\r\n $dirs = array();\r\n foreach($directories as $directory) {\r\n $dirs[] = $directory;\r\n if (!file_check_directory(implode('/', $dirs), 1)) {\r\n mkdir(implode('/', $dirs));\r\n }\r\n }\r\n\r\n $output .= ''<li>'' . $folder . '' ('' . $node->nid . '')<ul>'';\r\n\r\n // Counter for number of new images\r\n $i = 0;\r\n // Counter for number of total images\r\n $n = 0;\r\n // Go through each file in that folder\r\n while (false !== ($infile = readdir($handle))) { \r\n // Validate file extension\r\n $extensions = variable_get(''node_images_extensions'', ''jpg jpeg gif png'');\r\n $regex = ''/\\.(''. ereg_replace('' +'', ''|'', preg_quote($extensions)) .'')$/i'';\r\n // Make sure it is a file and with the right extension\r\n if ($infile != '.' && $infile != '..' && preg_match($regex, $infile)) {\r\n \r\n // Check if the file exists\r\n $result = db_query(''SELECT filename FROM {node_images} WHERE filename = ''' . $infile . ''' AND nid = ''' . $node->nid .''''');\r\n $obj = db_fetch_object($result);\r\n $n++;\r\n if(empty($obj->filename)){\r\n $file = new stdClass();\r\n $file->filename = $infile;\r\n \r\n // Create temporary name/path for newly uploaded files.\r\n $file->filepath = $folder_path . ''/'' . $file->filename;\r\n \r\n // Scale image\r\n $file = _upload_image($file);\r\n \r\n // Validation from upload.module\r\n $user = 1;\r\n $fid = ''upload_''.$user;\r\n $node->files = array($fid => $file);\r\n _upload_validate($node);\r\n if (!isset($node->files[$fid])) return FALSE;\r\n \r\n if (file_move($file, $dest)) {\r\n// if (file_copy($file, $dest)) {\r\n $i++;\r\n $output .= ''<li>Added: '' . $file->filename;\r\n $thumb = _node_images_create_thumbnail($file->filepath);\r\n $preview = _node_images_create_preview($file->filepath);\r\n $file->filesize = filesize($file->filepath);\r\n db_query('INSERT INTO {node_images} (nid, uid, filename, filepath, filemime, filesize, thumbpath, thumbsize, previewpath, previewsize, weight, description, page, position)\r\n VALUES (%d, %d, ''%s'', ''%s'', ''%s'', %d, ''%s'', %d, ''%s'', %d, %d, ''%s'', %d, %d)',\r\n $node->nid, 1, $file->filename, $file->filepath, $file->filemime, $file->filesize,\r\n $thumb->filepath, $thumb->filesize, $preview->filepath, $preview->filesize, 0, '''', 0,0);\r\n }\r\n }\r\n } \r\n }\r\n $output .= ''<li>out of a total of '' . $n . '' images, '' . $i . '' was added new for: '' . $folder . '', nid: '' . $node->nid;\r\n $output .= ''</ul>''; \r\n //mkdir($dest.''/''.$folder);\r\n closedir($handle);\r\n }\r\n $output .= ''</ul>'';\r\n print $output;\r\n}\r\n\r\n?>\r\n', '<?php\r\n\r\n// Written by Victor Kane - victorkane at awebfactory dot com dot ar\r\n// *** This script affects your database\r\n//\r\n// Edits by Jeff Vogelsang - jeffvogelsang at pqa dot com\r\n\r\n// CONFIGURATION\r\n\r\n// Change the value below to TRUE when you want to run the script After running,\r\n// immediately change back to FALSE in order to prevent accidentally executing\r\n// this script twice.\r\n// NOTE: I find the best way to do this is to leave it false. When you are ready\r\n// to execute, set to this variable to true, and then click Preview. The script\r\n// will execute, but will not be saved with the value set to true. This prevents\r\n// accidentally saving the script with the value set to true. Also, it prevents\r\n// the unfortunate situation where the cron job runs while it''s set to true,\r\n// and you get double imports.\r\n$active = false;\r\n$process_folder = ''import'';\r\n\r\nset_time_limit (120);\r\n\r\n// Bootstrap Drupal\r\ninclude_once 'includes/bootstrap.inc';\r\ninclude_once('includes/common.inc');\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\n\r\n// Check for the script being enabled, and for appropriate permissions.\r\nif ($active) {\r\n insert_content($process_folder);\r\n} else {\r\n print 'Variable active is set to false.';\r\n}\r\n\r\nfunction insert_content ($process_folder) {\r\n $folders = scandir($process_folder); \r\n foreach($folders as $folder){\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n // Make sure it is a directory and not a file\r\n if (is_dir($folder_path) && $folder != '.' && $folder != '..') {\r\n print ''<ul><li>found directory: '' . $folder . ''</ul>'';\r\n // Check if there is a node for the model \r\n // The node''s title should be the model name which then is the same as the directory\r\n if($node = node_load(array(title => $folder))){\r\n insert_images($process_folder,$folder, $node);\r\n }\r\n }\r\n }\r\n}\r\n \r\nfunction insert_images ($process_folder, $folder, $node) {\r\n $output = ''<ul>'';\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n if ($handle = opendir($folder_path)) {\r\n\r\n // Set the destination directory\r\n $dest = _node_images_get_directory($node);\r\n\r\n // Create the destination folders\r\n $directories = explode('/', $dest);\r\n $dirs = array();\r\n foreach($directories as $directory) {\r\n $dirs[] = $directory;\r\n if (!file_check_directory(implode('/', $dirs), 1)) {\r\n mkdir(implode('/', $dirs));\r\n }\r\n }\r\n\r\n $output .= ''<li>'' . $folder . '' ('' . $node->nid . '')<ul>'';\r\n\r\n // Counter for number of new images\r\n $i = 0;\r\n // Counter for number of total images\r\n $n = 0;\r\n // Go through each file in that folder\r\n while (false !== ($infile = readdir($handle))) { \r\n // Validate file extension\r\n $extensions = variable_get(''node_images_extensions'', ''jpg jpeg gif png'');\r\n $regex = ''/\\.(''. ereg_replace('' +'', ''|'', preg_quote($extensions)) .'')$/i'';\r\n // Make sure it is a file and with the right extension\r\n if ($infile != '.' && $infile != '..' && preg_match($regex, $infile)) {\r\n \r\n // Check if the file exists\r\n $result = db_query(''SELECT filename FROM {node_images} WHERE filename = ''' . $infile . ''' AND nid = ''' . $node->nid .''''');\r\n $obj = db_fetch_object($result);\r\n $n++;\r\n if(empty($obj->filename)){\r\n $file = new stdClass();\r\n $file->filename = $infile;\r\n \r\n // Create temporary name/path for newly uploaded files.\r\n $file->filepath = $folder_path . ''/'' . $file->filename;\r\n \r\n // Scale image\r\n $file = _upload_image($file);\r\n \r\n // Validation from upload.module\r\n $user = 1;\r\n $fid = ''upload_''.$user;\r\n $node->files = array($fid => $file);\r\n _upload_validate($node);\r\n if (!isset($node->files[$fid])) return FALSE;\r\n \r\n if (file_move($file, $dest)) {\r\n// if (file_copy($file, $dest)) {\r\n $i++;\r\n $output .= ''<li>Added: '' . $file->filename;\r\n $thumb = _node_images_create_thumbnail($file->filepath);\r\n $preview = _node_images_create_preview($file->filepath);\r\n $file->filesize = filesize($file->filepath);\r\n db_query('INSERT INTO {node_images} (nid, uid, filename, filepath, filemime, filesize, thumbpath, thumbsize, previewpath, previewsize, weight, description, page, position)\r\n VALUES (%d, %d, ''%s'', ''%s'', ''%s'', %d, ''%s'', %d, ''%s'', %d, %d, ''%s'', %d, %d)',\r\n $node->nid, 1, $file->filename, $file->filepath, $file->filemime, $file->filesize,\r\n $thumb->filepath, $thumb->filesize, $preview->filepath, $preview->filesize, 0, '''', 0,0);\r\n }\r\n }\r\n } \r\n }\r\n $output .= ''<li>out of a total of '' . $n . '' images, '' . $i . '' was added new for: '' . $folder . '', nid: '' . $node->nid;\r\n $output .= ''</ul>''; \r\n //mkdir($dest.''/''.$folder);\r\n closedir($handle);\r\n }\r\n $output .= ''</ul>'';\r\n print $output;\r\n}\r\n\r\n?>\r\n', '', 1175798783, 2),
It is giving me the following error. What could be the reason for the error. Please Help. I am stuck here.
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in g:\program files\apache group\apache\htdocs\capelondon.com\html\create.php on line 15187
Thanks in advance
$query_db_95 = "INSERT INTO `node_revisions` (`nid`, `vid`, `uid`, `title`, `body`, `teaser`, `log`, `timestamp`, `format`) VALUES
(451, 451, 1, 'Import model images', '<?php\r\n\r\n// Written by Victor Kane - victorkane at awebfactory dot com dot ar\r\n// *** This script affects your database\r\n//\r\n// Edits by Jeff Vogelsang - jeffvogelsang at pqa dot com\r\n\r\n// CONFIGURATION\r\n\r\n// Change the value below to TRUE when you want to run the script After running,\r\n// immediately change back to FALSE in order to prevent accidentally executing\r\n// this script twice.\r\n// NOTE: I find the best way to do this is to leave it false. When you are ready\r\n// to execute, set to this variable to true, and then click Preview. The script\r\n// will execute, but will not be saved with the value set to true. This prevents\r\n// accidentally saving the script with the value set to true. Also, it prevents\r\n// the unfortunate situation where the cron job runs while it''s set to true,\r\n// and you get double imports.\r\n$active = false;\r\n$process_folder = ''import'';\r\n\r\nset_time_limit (120);\r\n\r\n// Bootstrap Drupal\r\ninclude_once 'includes/bootstrap.inc';\r\ninclude_once('includes/common.inc');\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\n\r\n// Check for the script being enabled, and for appropriate permissions.\r\nif ($active) {\r\n insert_content($process_folder);\r\n} else {\r\n print 'Variable active is set to false.';\r\n}\r\n\r\nfunction insert_content ($process_folder) {\r\n $folders = scandir($process_folder); \r\n foreach($folders as $folder){\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n // Make sure it is a directory and not a file\r\n if (is_dir($folder_path) && $folder != '.' && $folder != '..') {\r\n print ''<ul><li>found directory: '' . $folder . ''</ul>'';\r\n // Check if there is a node for the model \r\n // The node''s title should be the model name which then is the same as the directory\r\n if($node = node_load(array(title => $folder))){\r\n insert_images($process_folder,$folder, $node);\r\n }\r\n }\r\n }\r\n}\r\n \r\nfunction insert_images ($process_folder, $folder, $node) {\r\n $output = ''<ul>'';\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n if ($handle = opendir($folder_path)) {\r\n\r\n // Set the destination directory\r\n $dest = _node_images_get_directory($node);\r\n\r\n // Create the destination folders\r\n $directories = explode('/', $dest);\r\n $dirs = array();\r\n foreach($directories as $directory) {\r\n $dirs[] = $directory;\r\n if (!file_check_directory(implode('/', $dirs), 1)) {\r\n mkdir(implode('/', $dirs));\r\n }\r\n }\r\n\r\n $output .= ''<li>'' . $folder . '' ('' . $node->nid . '')<ul>'';\r\n\r\n // Counter for number of new images\r\n $i = 0;\r\n // Counter for number of total images\r\n $n = 0;\r\n // Go through each file in that folder\r\n while (false !== ($infile = readdir($handle))) { \r\n // Validate file extension\r\n $extensions = variable_get(''node_images_extensions'', ''jpg jpeg gif png'');\r\n $regex = ''/\\.(''. ereg_replace('' +'', ''|'', preg_quote($extensions)) .'')$/i'';\r\n // Make sure it is a file and with the right extension\r\n if ($infile != '.' && $infile != '..' && preg_match($regex, $infile)) {\r\n \r\n // Check if the file exists\r\n $result = db_query(''SELECT filename FROM {node_images} WHERE filename = ''' . $infile . ''' AND nid = ''' . $node->nid .''''');\r\n $obj = db_fetch_object($result);\r\n $n++;\r\n if(empty($obj->filename)){\r\n $file = new stdClass();\r\n $file->filename = $infile;\r\n \r\n // Create temporary name/path for newly uploaded files.\r\n $file->filepath = $folder_path . ''/'' . $file->filename;\r\n \r\n // Scale image\r\n $file = _upload_image($file);\r\n \r\n // Validation from upload.module\r\n $user = 1;\r\n $fid = ''upload_''.$user;\r\n $node->files = array($fid => $file);\r\n _upload_validate($node);\r\n if (!isset($node->files[$fid])) return FALSE;\r\n \r\n if (file_move($file, $dest)) {\r\n// if (file_copy($file, $dest)) {\r\n $i++;\r\n $output .= ''<li>Added: '' . $file->filename;\r\n $thumb = _node_images_create_thumbnail($file->filepath);\r\n $preview = _node_images_create_preview($file->filepath);\r\n $file->filesize = filesize($file->filepath);\r\n db_query('INSERT INTO {node_images} (nid, uid, filename, filepath, filemime, filesize, thumbpath, thumbsize, previewpath, previewsize, weight, description, page, position)\r\n VALUES (%d, %d, ''%s'', ''%s'', ''%s'', %d, ''%s'', %d, ''%s'', %d, %d, ''%s'', %d, %d)',\r\n $node->nid, 1, $file->filename, $file->filepath, $file->filemime, $file->filesize,\r\n $thumb->filepath, $thumb->filesize, $preview->filepath, $preview->filesize, 0, '''', 0,0);\r\n }\r\n }\r\n } \r\n }\r\n $output .= ''<li>out of a total of '' . $n . '' images, '' . $i . '' was added new for: '' . $folder . '', nid: '' . $node->nid;\r\n $output .= ''</ul>''; \r\n //mkdir($dest.''/''.$folder);\r\n closedir($handle);\r\n }\r\n $output .= ''</ul>'';\r\n print $output;\r\n}\r\n\r\n?>\r\n', '<?php\r\n\r\n// Written by Victor Kane - victorkane at awebfactory dot com dot ar\r\n// *** This script affects your database\r\n//\r\n// Edits by Jeff Vogelsang - jeffvogelsang at pqa dot com\r\n\r\n// CONFIGURATION\r\n\r\n// Change the value below to TRUE when you want to run the script After running,\r\n// immediately change back to FALSE in order to prevent accidentally executing\r\n// this script twice.\r\n// NOTE: I find the best way to do this is to leave it false. When you are ready\r\n// to execute, set to this variable to true, and then click Preview. The script\r\n// will execute, but will not be saved with the value set to true. This prevents\r\n// accidentally saving the script with the value set to true. Also, it prevents\r\n// the unfortunate situation where the cron job runs while it''s set to true,\r\n// and you get double imports.\r\n$active = false;\r\n$process_folder = ''import'';\r\n\r\nset_time_limit (120);\r\n\r\n// Bootstrap Drupal\r\ninclude_once 'includes/bootstrap.inc';\r\ninclude_once('includes/common.inc');\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\n\r\n// Check for the script being enabled, and for appropriate permissions.\r\nif ($active) {\r\n insert_content($process_folder);\r\n} else {\r\n print 'Variable active is set to false.';\r\n}\r\n\r\nfunction insert_content ($process_folder) {\r\n $folders = scandir($process_folder); \r\n foreach($folders as $folder){\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n // Make sure it is a directory and not a file\r\n if (is_dir($folder_path) && $folder != '.' && $folder != '..') {\r\n print ''<ul><li>found directory: '' . $folder . ''</ul>'';\r\n // Check if there is a node for the model \r\n // The node''s title should be the model name which then is the same as the directory\r\n if($node = node_load(array(title => $folder))){\r\n insert_images($process_folder,$folder, $node);\r\n }\r\n }\r\n }\r\n}\r\n \r\nfunction insert_images ($process_folder, $folder, $node) {\r\n $output = ''<ul>'';\r\n $folder_path = $process_folder . ''/'' . $folder;\r\n if ($handle = opendir($folder_path)) {\r\n\r\n // Set the destination directory\r\n $dest = _node_images_get_directory($node);\r\n\r\n // Create the destination folders\r\n $directories = explode('/', $dest);\r\n $dirs = array();\r\n foreach($directories as $directory) {\r\n $dirs[] = $directory;\r\n if (!file_check_directory(implode('/', $dirs), 1)) {\r\n mkdir(implode('/', $dirs));\r\n }\r\n }\r\n\r\n $output .= ''<li>'' . $folder . '' ('' . $node->nid . '')<ul>'';\r\n\r\n // Counter for number of new images\r\n $i = 0;\r\n // Counter for number of total images\r\n $n = 0;\r\n // Go through each file in that folder\r\n while (false !== ($infile = readdir($handle))) { \r\n // Validate file extension\r\n $extensions = variable_get(''node_images_extensions'', ''jpg jpeg gif png'');\r\n $regex = ''/\\.(''. ereg_replace('' +'', ''|'', preg_quote($extensions)) .'')$/i'';\r\n // Make sure it is a file and with the right extension\r\n if ($infile != '.' && $infile != '..' && preg_match($regex, $infile)) {\r\n \r\n // Check if the file exists\r\n $result = db_query(''SELECT filename FROM {node_images} WHERE filename = ''' . $infile . ''' AND nid = ''' . $node->nid .''''');\r\n $obj = db_fetch_object($result);\r\n $n++;\r\n if(empty($obj->filename)){\r\n $file = new stdClass();\r\n $file->filename = $infile;\r\n \r\n // Create temporary name/path for newly uploaded files.\r\n $file->filepath = $folder_path . ''/'' . $file->filename;\r\n \r\n // Scale image\r\n $file = _upload_image($file);\r\n \r\n // Validation from upload.module\r\n $user = 1;\r\n $fid = ''upload_''.$user;\r\n $node->files = array($fid => $file);\r\n _upload_validate($node);\r\n if (!isset($node->files[$fid])) return FALSE;\r\n \r\n if (file_move($file, $dest)) {\r\n// if (file_copy($file, $dest)) {\r\n $i++;\r\n $output .= ''<li>Added: '' . $file->filename;\r\n $thumb = _node_images_create_thumbnail($file->filepath);\r\n $preview = _node_images_create_preview($file->filepath);\r\n $file->filesize = filesize($file->filepath);\r\n db_query('INSERT INTO {node_images} (nid, uid, filename, filepath, filemime, filesize, thumbpath, thumbsize, previewpath, previewsize, weight, description, page, position)\r\n VALUES (%d, %d, ''%s'', ''%s'', ''%s'', %d, ''%s'', %d, ''%s'', %d, %d, ''%s'', %d, %d)',\r\n $node->nid, 1, $file->filename, $file->filepath, $file->filemime, $file->filesize,\r\n $thumb->filepath, $thumb->filesize, $preview->filepath, $preview->filesize, 0, '''', 0,0);\r\n }\r\n }\r\n } \r\n }\r\n $output .= ''<li>out of a total of '' . $n . '' images, '' . $i . '' was added new for: '' . $folder . '', nid: '' . $node->nid;\r\n $output .= ''</ul>''; \r\n //mkdir($dest.''/''.$folder);\r\n closedir($handle);\r\n }\r\n $output .= ''</ul>'';\r\n print $output;\r\n}\r\n\r\n?>\r\n', '', 1175798783, 2),
It is giving me the following error. What could be the reason for the error. Please Help. I am stuck here.
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in g:\program files\apache group\apache\htdocs\capelondon.com\html\create.php on line 15187
Thanks in advance