如何在laravel中编写空白php?

时间:2019-02-09 21:58:59

标签: php laravel

您好,我想向laravel应用添加php代码

从这里: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吗?

但是我怎么了?

谢谢您的帮助! :)

1 个答案:

答案 0 :(得分:1)

答案确实存在

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');

,然后在网址框中,您只需将其命名为

  

urlpath / iptc / foo / bar / doe

因此控制器会将其识别为

$ rec = foo,

$ data =条形

$ value = doe