iskiz
Новичок
Есть ПХП код, в котором много лишних символов(например знак "\" в ненужных местах), из-за которых он не работает. Пробовал почистить сам, но ничего не получилось - скрипт не запускался все равно. Подскажите, что тут нужно поудалять?
Извините за дурной вопрос...
Заранее спасибо.
Извините за дурной вопрос...
Заранее спасибо.
PHP:
<?php
/////////////////////
// Parameters need to be passed in through the URL\'s query string:
// pl absolute path of local playlistfile starting with \"/\" (e.g. /images/toast.jpg)
/////////////////////
/////////////////////
// CODE STARTS HERE
/////////////////////
if (!isset($_GET[\'pl\']))
{
header(\'HTTP/1.1 400 Bad Request\');
echo \'Error: no playlist was specified\';
exit();
}
define(\'MEMORY_TO_ALLOCATE\', \'8M\');
define(\'CURRENT_DIR\', dirname(__FILE__));
define(\'DOCUMENT_ROOT\', $_SERVER[\'DOCUMENT_ROOT\']);
// Playlists must be local files, so for convenience we strip the domain if it\'s there
$playlist = preg_replace(\'/^(s?f|ht)tps?:\/\/[^\/]+/i\', \'\', (string) $_GET[\'pl\']);
// For security, directories cannot contain \':\', playlist files cannot contain \'..\' or \'<\', and
// images must start with \'/\'
if ($playlist{0} != \'/\' || strpos(dirname($playlist), \':\') || preg_match(\'/(\.\.|<|>)/\', $playlist))
{
header(\'HTTP/1.1 400 Bad Request\');
echo \'Error: malformed playlist path. Playlist paths must begin with \'/\'\';
exit();
}
// If the playlist doesn\'t exist, or we haven\'t been told what it is, there\'s nothing
// that we can do
if (!$playlist)
{
header(\'HTTP/1.1 400 Bad Request\');
echo \'Error: no playlist file was specified\';
exit();
}
// Strip the possible trailing slash off the document root
$docRoot = preg_replace(\'/\/$/\', \'\', DOCUMENT_ROOT);
if (!file_exists($docRoot . $playlist))
{
header(\'HTTP/1.1 404 Not Found\');
echo \'Error: playlist file does not exist: \' . $docRoot . $playlist;
exit();
}
$playlist_string = file_get_contents( \'http://\' . \'server.com\' . $playlist);
$decoded_playlist = json_decode($playlist_string, true);
// для дебага
// echo \'<h2>Декодированный плейлист</h2><pre>\';
// print_r ($decoded_playlist);
// echo \'</pre>\';
function encode_urls($decoded_playlist) {
date_default_timezone_set(\'Europe/Helsinki\');
foreach ($decoded_playlist as &$episode) {
foreach ($episode as &$url) {
$secret = \'yoursecretword\';
$fname = basename($url[\'file\']);
$ts = sprintf(\"%08x\",strtotime(\"now\"));
$dirname = dirname($url[\'file\']);
$url[\'file\'] = $dirname . \'/\' . md5($fname . $ts . $secret) . \"/{$ts}/{$fname}\";
}
}
return $decoded_playlist;
}
$decoded_playlist = encode_urls($decoded_playlist);
// для дебага
// echo \'<br /> <br />\';
//
// foreach ($decoded_playlist as $episode) {
// echo \'<pre>\';
// foreach ($episode as $url) {
// print_r($url);
// }
// echo \'</pre>\';
// }
// для дебага
// echo \'<h2>Декодированный плейлист 2</h2><pre>\';
// print_r ($decoded_playlist);
// echo \'</pre>\';
//
// echo \'<h2>Закодированный JSON плейлист 2</h2><pre>\';
print_r (json_encode($decoded_playlist));
// echo \'</pre>\';
?>