我在创建新的laravel项目时遇到了一点小问题。昨天我创建了一个没有问题的新项目,但是今天我收到了这个错误:
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 new projectName
<?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';
}
}发布于 2016-12-11 03:51:48
检查在安装过程中是否有一些英文字符无法阅读,如à或ö。
示例: C:\Users\User\Informàtica\Web Projects -->必须是--> C:\Users\User\Informatica\Web Projects
发布于 2015-06-29 19:05:13
最近我也遇到了这个错误,但是当我在几周前安装它的时候,它是好的,我对它做了一些研究,但没有发现任何有用的东西。然后我尝试了以下方法:
Composer.json再次运行此命令在ur cmd composer全局需要“C:/Users/(your_profile_name)/AppData/Roaming/Composer /
发布于 2017-11-20 20:59:04
我可以调试和解决这个问题。对我来说这是一个网络问题(防火墙)!
我观察到“laravel new”命令在我的家庭网络中工作得很好,但我在办公室网络中得到了以下错误,
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;
}我尝试在浏览器中输入网址,但收到防火墙错误,因为网址包含.zip扩展名。因此,我要求我的网络管理员排除对此URL的检查。
然后,项目成功创建,没有任何问题。
因此,解决方案是,尝试从浏览器访问网址(http://cabinet.laravel.com/latest.zip)。如果它不工作,请联系网络管理员或尝试从您的家庭/移动网络执行命令。希望这能有所帮助。谢谢。
https://stackoverflow.com/questions/29375668
复制相似问题