[英]How to use pathinfo in php?
I am working on a php code as shown below on which Line#A prints the following array (shown below php code). 我正在开发一个php代码,如下所示,Line#A打印下面的数组(如下面的php代码所示)。 My code doesn't seems to go inside switch statement.
我的代码似乎没有进入switch语句。 I am not sure why.
我不知道为什么。
I added print_r($parts)
at Line A in order to print the value of $parts. 我在A行添加了
print_r($parts)
以打印$ parts的值。
php code:
php代码:
<?php
if (!empty($_POST['id']))
{
for($i=0; $i <count($mp4_files); $i++) {
if($i == $_POST['id']) {
$f = $mp4_files[$i];
$parts = pathinfo($f);
print_r($parts); // Line A
switch ($parts['extension'])
{
echo "Hello World"; // Line B
case 'mp4' :
$filePath = $src_dir . DS . $f;
system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);
}
}
}
}
?>
Output (Line#A):
输出(线#A):
Array
(
[dirname] => .
[basename] => hello.mp4
[extension] => mp4
[filename] => hello
)
I have used echo "Hello World"
at Line B but for some reasons, its not getting printed and throwing 500 internal server error
on console. 我在B行使用了
echo "Hello World"
但由于某些原因,它没有被打印并在控制台上抛出500 internal server error
。
Problem Statement: 问题陈述:
I am wondering what changes I should make in the php code so that it goes inside switch statement. 我想知道我应该在php代码中做出哪些更改,以便它进入switch语句。
The error 500 is caused by echo "Hello World"
at Line B which is outside of case mp4
. 错误500由线路B处的
echo "Hello World"
引起,其在情况mp4
之外。
Your switch statement should be like this. 你的switch语句应该是这样的。
switch ($parts['extension']) {
case 'mp4':
echo "hello world";
$filePath = $src_dir . DS . $f;
system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.