我在創建新的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';
}
}
它會幫助人們幫助你,如果你提供了確切的命令之前,你得到了上述錯誤信息 – 2015-03-31 18:23:49
我得到了同樣的錯誤..搜索無處不在網上...仍然沒有答案:( – 2015-04-05 12:02:41
我也面臨同樣的問題在Ubuntu 14.04上運行的命令是「laravel new todo」,現在使用替代方法「composer create-project laravel/laravel todo」來創建項目,這很好, – 2015-04-08 06:21:01