2017-07-18 151 views
1

原谅这里的表面跛脚。我正在使用共享主机,只能访问cpanel,主机不愿意代表我安装composer或PHPWord。是否可以通过从github下载ZIP来安装PHPWord?谢谢没有作曲家的PHPWord安装

+0

由于客户端/工作是共享主机限制吗?限制自己在第三节的时候听起来并不好玩。 – castis

+0

@castis主机刚说他们不支持它,客户已经做了12个月的订阅。不过,从一开始我并不认为我需要额外的组件将word转换为pdf – Ojchris

回答

3

您可以在本地使用Composer,然后将文件上传到服务器。

我问起这个位置:Using Composer locally then uploading files through FTP

基本上,如果你不能在服务器上运行作曲,本地使用它,然后将所需的文件复制到服务器。

你应该使用它的原因是因为它会为你下载依赖关系,而不必手动配置一些东西。这是作曲家:)

composer require phpoffice/phpword 

Using version ^0.13.0 for phpoffice/phpword 

./composer.json has been created 

Loading composer repositories with package information 
Updating dependencies (including require-dev) 

    - Installing pclzip/pclzip (2.8.2) 
    Downloading: 100%   

    - Installing phpoffice/common (v0.2.6) 
    Downloading: 100%   

    - Installing zendframework/zend-stdlib (2.4.13) 
    Downloading: 100%   

    - Installing zendframework/zend-validator (2.4.13) 
    Downloading: 100%   

    - Installing zendframework/zend-escaper (2.4.13) 
    Downloading: 100%   

    - Installing phpoffice/phpword (v0.13.0) 
    Downloading: 100% 
+0

谢谢。但任何想法如何获得zend组件:Zend \ Escaper组件 Zend \ Stdlib组件 Zend \ Validator组件,因为我没有使用Zend框架? – Ojchris

+0

这就是为什么你应该使用Composer。因为它会得到你的依赖。 – Andy

+0

是的,我忘了。谢谢 – Ojchris

-1

下载PHpWord ZIP文件从这里非常多的点:https://github.com/PHPOffice/PHPWord/archive/develop.zip

来源:: https://github.com/PHPOffice/PHPWord

PHPWord需要以下扩展名:

  • PHP 5.3.3+
  • XML分析器扩展
  • 的Zend \逃避者部件
  • 的Zend \ STDLIB部件
  • 的Zend \验证程序组件
  • zip扩展(可选,用于写和OOXML ODF)
  • GD扩展(可选,用于增加图象)
  • XMLWriter的延伸部(可选的,用于写和OOXML ODF)
  • XSL扩展(可选,用于应用XSL样式表到模板)
  • DOMPDF库(可选的,用来写PDF)

PHPWord库的基本用法。 https://github.com/PHPOffice/PHPWord

+0

谢谢。但任何想法如何获得zend组件:Zend \ Escaper组件 Zend \ Stdlib组件 Zend \ Validator组件,因为我没有使用Zend框架? – Ojchris

0

是的,我一直这样做。对于PHPWord,我会从GitHub下载zip文件并将src文件夹的内容移动到名为“lib \ PhpOffice \ PhpWord”的目录中。您将需要一个PHP类加载器。我总是使用它来自动加载,只要类是正确命名空间的,看起来就是这种情况。

$GLOBALS['class_path'] = array(__DIR__ . '/lib', __DIR__); 

// Set-up class_path superglobal variable using php include_path as basis 
if (!array_key_exists('class_path', $GLOBALS)) { 
    $GLOBALS['class_path'] = array(); 
    foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { 
     // substitute __DIR__ path for '.' instead 
     if ($path == '.') { 
      array_push($GLOBALS['class_path'], realpath(__DIR__)); 
      continue; 
     } 
     array_push($GLOBALS['class_path'], realpath($path)); 
    } 
} 

if (!function_exists('import')): 
function import($package = '') { 
    if (empty($package)) { 
     trigger_error("Package path must be specified.", E_USER_ERROR); 
    } 
    $package_bits = explode('\\', $package); 
    $package_path = implode(DIRECTORY_SEPARATOR, $package_bits) . '.php'; 
    foreach ($GLOBALS['class_path'] as $path) { 
     $file = $path . DIRECTORY_SEPARATOR . $package_path; 
     if (file_exists($file)) { 
      require_once($file); 
      $entity_name = implode('\\', $package_bits); 
      if (!(class_exists($entity_name, false) || 
       interface_exists($entity_name, false) 
       || trait_exists($entity_name, false))) { 
      $caller = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; 
      trigger_error("Entity '" . $package . "' not found in file '" . $package_path . "' for import called in " . 
        $caller['file'] . " on line " . $caller['line'], E_USER_ERROR); 
      } 
      return; 
     } 
    } 
} 
endif; 

spl_autoload_register('import'); 

设置你的$ GLOBALS [ 'CLASS_PATH']到 '的lib' 目录的位置,一定要使用 '使用' 试图实例PHPWord之前需要。

希望这会有所帮助!

+0

谢谢你去了一英里。两件事:走这条路1)任何想法如何获得Zend组件:Zend \ Escaper组件 Zend \ Stdlib组件 因为我没有使用Zend框架,Zend \ Validator组件? 2)我正在使用codeigniter框架,我很感谢您关于如何使用类加载代码的建议。谢谢 – Ojchris

+0

我不会推荐这个。如果您按照我的答案使用Composer,则无需执行任何操作。它会为您创建自动加载器。 – Andy

+0

@Ojchris - 听起来像你有1)想通了。至于2,CI有它自己的类加载器。我记得,它有一个目录下的应用程序,你安装自己的库。我记得Zend的安装以及我为我所从事的网站下载的一些附加库。不幸的是,我现在正在那个位置上空白。我会尝试窥视我的一个旧项目并查看该目录的位置。 – Borgboy