首页 > 解决方案 > 如何在 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?

但我做错了什么?

感谢您的帮助!!:)

标签: phplaravel

解决方案


答案就在那里

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 = 条形图,

$价值=母鹿


推荐阅读