php - 如何在 laravel 中编写空白 php?
问题描述
您好,我想将 php 代码添加到我的 laravel 应用程序
从这里: http: //php.net/manual/de/function.iptcembed.php
我试图在我的控制器中这样做:
<?php
function iptc($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
if($length < 0x8000)
{
$retval .= chr($length >> 8) . chr($length & 0xFF);
}
else
{
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
}
return $retval . $value;
}
// Path to jpeg file
$path = 'public\images\test.jpg';
// Set the IPTC tags
$iptc = array(
'2#120' => 'Test image',
'2#116' => 'Copyright 2008-2009, The PHP Group'
);
// Convert the IPTC tags into binary code
$data = '';
foreach($iptc as $tag => $string)
{
$tag = substr($tag, 2);
$data .= iptc_make_tag(2, $tag, $string);
}
// Embed the IPTC data
$content = iptcembed($data, $path);
// Write the new image data out to the file.
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
?>
Note
我想在我的路线中调用该函数:
Route::get('/iptc', 'MetaController@iptc');
但现在它向我显示了这个错误:
函数 App\Http\Controllers\MetaController::iptc() 的参数太少,通过了 0 个,预期正好 3 个
有谁知道是什么问题?
我虽然可以在 laravel 中编写普通的 php?
但我做错了什么?
感谢您的帮助!!:)
解决方案
答案就在那里
Too few arguments to function App\Http\Controllers\MetaController::iptc(), 0 passed and exactly 3 expected
函数 @iptc 期望 3 个参数,但你传递了 0 个参数
因此,在您的路线中,您需要更改为
Route::get('/iptc/{rec}/{data}/{value}', 'MetaController@iptc');
然后在 url 框中,您只需将其称为
urlpath/iptc/foo/bar/doe
所以控制器会将其识别为
$rec = 富,
$data = 条形图,
$价值=母鹿
推荐阅读
- xamarin - xamarin 在 webview 上形成标签(如水印)
- qt - ./app_name:无法执行二进制文件:执行格式错误
- karate - 如何验证嵌套数组元素是否使用空手道排序
- azure - 请验证 Azure 搜索服务是否已启动,重新启动 WebApp 并重试
- javascript - 为什么两个DIV不能在父DIV下拖动?
- powershell - 如何要求 PowerShell 复制标识重复并将其答案以逗号分隔?
- python-3.x - 尝试更改框架时出现 Selenium Python 异常错误
- c# - 使用 HttpClient.GetAsync 块确实注册取消令牌
- swift - 斯威夫特 macOS | 设置(切换)暗模式和亮模式
- json - 在 wso2 esb 中连接两个 JSON 响应