2015-03-31 59 views
1

我在創建新的laravel項目時遇到了一些問題。昨天,我創建了沒有問題的新項目,但今天我得到這個錯誤:Laravel 5 - PHP警告:ZipArchive :: extractTo():無效或單元化Zip對象

PHP Warning: ZipArchive::extractTo(): Invalid or unitialized Zip object in /home/tomas/.composer/vendor/laravel/installer/src/NewCommand.php on line 114 
PHP Warning: ZipArchive::close(): Invalid or unitialized Zip object in /home/tomas/.composer/vendor/laravel/installer/src/NewCommand.php on line 116 

,我想我沒有權限/home/tomas/.composer/vendor/laravel/installer/src/NewCommand。 PHP,但我有所有權利。

難道你不知道哪裏會出問題嗎?謝謝。

編輯:

我只需運行命令:laravel新項目名

<?php namespace Laravel\Installer\Console; 

use ZipArchive; 
use Symfony\Component\Process\Process; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Output\OutputInterface; 

class NewCommand extends \Symfony\Component\Console\Command\Command { 

/** 
* Configure the command options. 
* 
* @return void 
*/ 
protected function configure() 
{ 
    $this->setName('new') 
      ->setDescription('Create a new Laravel application.') 
      ->addArgument('name', InputArgument::REQUIRED); 
} 

/** 
* Execute the command. 
* 
* @param InputInterface $input 
* @param OutputInterface $output 
* @return void 
*/ 
protected function execute(InputInterface $input, OutputInterface $output) 
{ 
    $this->verifyApplicationDoesntExist(
     $directory = getcwd().'/'.$input->getArgument('name'), 
     $output 
    ); 

    $output->writeln('<info>Crafting application...</info>'); 

    $this->download($zipFile = $this->makeFilename()) 
     ->extract($zipFile, $directory) 
     ->cleanUp($zipFile); 

    $composer = $this->findComposer(); 

    $commands = array(
     $composer.' run-script post-install-cmd', 
     $composer.' run-script post-create-project-cmd', 
    ); 

    $process = new Process(implode(' && ', $commands), $directory, null, null, null); 

    $process->run(function($type, $line) use ($output) 
    { 
     $output->write($line); 
    }); 

    $output->writeln('<comment>Application ready! Build something amazing.</comment>'); 
} 

/** 
* Verify that the application does not already exist. 
* 
* @param string $directory 
* @return void 
*/ 
protected function verifyApplicationDoesntExist($directory, OutputInterface $output) 
{ 
    if (is_dir($directory)) 
    { 
     $output->writeln('<error>Application already exists!</error>'); 

     exit(1); 
    } 
} 

/** 
* Generate a random temporary filename. 
* 
* @return string 
*/ 
protected function makeFilename() 
{ 
    return getcwd().'/laravel_'.md5(time().uniqid()).'.zip'; 
} 

/** 
* Download the temporary Zip to the given file. 
* 
* @param string $zipFile 
* @return $this 
*/ 
protected function download($zipFile) 
{ 
    $response = \GuzzleHttp\get('http://cabinet.laravel.com/latest.zip')->getBody(); 

    file_put_contents($zipFile, $response); 

    return $this; 
} 

/** 
* Extract the zip file into the given directory. 
* 
* @param string $zipFile 
* @param string $directory 
* @return $this 
*/ 
protected function extract($zipFile, $directory) 
{ 
    $archive = new ZipArchive; 

    $archive->open($zipFile); 

    $archive->extractTo($directory); 

    $archive->close(); 

    return $this; 
} 

/** 
* Clean-up the Zip file. 
* 
* @param string $zipFile 
* @return $this 
*/ 
protected function cleanUp($zipFile) 
{ 
    @chmod($zipFile, 0777); 

    @unlink($zipFile); 

    return $this; 
} 

/** 
* Get the composer command for the environment. 
* 
* @return string 
*/ 
protected function findComposer() 
{ 
    if (file_exists(getcwd().'/composer.phar')) 
    { 
     return '"'.PHP_BINARY.'" composer.phar'; 
    } 

    return 'composer'; 
} 

} 
+0

它會幫助人們幫助你,如果你提供了確切的命令之前,你得到了上述錯誤信息 – 2015-03-31 18:23:49

+0

我得到了同樣的錯誤..搜索無處不在網上...仍然沒有答案:( – 2015-04-05 12:02:41

+1

我也面臨同樣的問題在Ubuntu 14.04上運行的命令是「laravel new todo」,現在使用替代方法「composer create-project laravel/laravel todo」來創建項目,這很好, – 2015-04-08 06:21:01

回答

0

最近我也得到了錯誤,但是當我安裝了幾個星期以前它是很好,我做了一些研究,但發現什麼都沒有幫助。然後,我後來試圖follwing方法:

  • 運行在烏爾CMD再次命令[作曲家全球需要 「laravel /安裝=〜1.1」]

  • 它會顯示:「更改當前目錄爲C:/Users /(your_profile_name)/ AppData/Roaming/Composer ./composer.json已更新「

  • 它會在更新完成後更新完成再次檢查。它會正常工作。

  • 礦工以這種方式工作。

2

檢查一下,如果在安裝過程中有一些字符不能像英文或ö一樣用英文朗讀。


實施例: C:\用戶\用戶\通知à蒂卡\ Web項目 - > 必須是 - > C:\用戶\用戶\通知一個蒂卡\ Web項目

-1

我只是在當前路徑我已經在創建文件夾使用的命令,它是這樣的:

laravel新larvIinstall

其中larvInstall不是路徑,也不是命令選項,只是文件夾的名稱。它工作得很好。

1

我能夠調試並解決此問題。事實證明,這對我來說是一個網絡問題(防火牆)!

我觀察到的「laravel新」在我的家庭網絡工作正常的命令,但我正在辦公室網絡下面的錯誤,

PHP Warning: ZipArchive::extractTo(): Invalid or unitialized Zip object in C:\Users\Rajesh Kumar Raj\AppData\Roaming\Composer\vendor\laravel\installer\src\NewCommand.php on line 157 

所以,我決定調試NewCommand.php文件。

我注意到下面的函數試圖通過調用URL http://cabinet.laravel.com/latest.zip

protected function download($zipFile, $version = 'master') 
{ 
    switch ($version) { 
     case 'develop': 
      $filename = 'latest-develop.zip'; 
      break; 
     case 'master': 
      $filename = 'latest.zip'; 
      break; 
    } 

    $response = (new Client)->get('http://cabinet.laravel.com/'.$filename); 

    file_put_contents($zipFile, $response->getBody()); 

    return $this; 
} 

我試着在我的瀏覽器中鍵入URL下載一個壓縮文件,我得到了一個防火牆錯誤,因爲URL包括.zip擴展。所以,我讓我的網絡管理員排除檢查這個URL。

然後項目成功創建沒有任何問題。

因此,解決方法是,嘗試從您的瀏覽器訪問URL(http://cabinet.laravel.com/latest.zip)。如果它不工作,請聯繫網絡管理員或嘗試從家庭/移動網絡執行命令。 希望這有助於。謝謝。

+0

請注意,我使用的是Composer版本1.5。 2和Laravel安裝程序版本1.4 – 2017-11-20 13:12:59

相關問題