ошибка в пхп объясните мне подробно

12
P
На сайте с 11.02.2018
Offline
8
860

Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct(pics,pics): �� ������ ����� �������� ����. (code: 2) in E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php:2 Stack trace: #0 E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php(2): DirectoryIterator->__construct('pics') #1 {main} thrown in E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php on line 2

index.php

<?php

$dh = new DirectoryIterator( "pics" );

$files = array( );
foreach( $dh as $file )
{
if ( preg_match( "/[.]jpg$/", $file ) ) $files []= "$file";
}
?>
<html>
<head>
<title>Slideshow</title>
<style>
body { background: black; }
#thumbnails { height: 140px; width: 100%; overflow: auto; }
#pic { text-align: center; height: 400px; padding: 20px; }
</style>
<script>
var image_list = [ <?php $first = true; foreach( $files as $image ) { ?>
<?php echo( $first ? "" : ", " ); ?>"<?php echo( $image ); ?>"
<?php $first = false; } ?>
];

var curimage = 0;

function switchimg( ind )
{
var image = image_list[ind];
var obj = document.getElementById( "selimg" );
obj.src = "scale.php?image="+image+"&y=400";
curimage = ind;
}

function nextimage( )
{
curimage++;
if ( curimage >= image_list.length ) curimage = 0;
switchimg( curimage );
}
window.setInterval( "nextimage( )", 2000 );
</script>
</head>
<body>
<div id="thumbnails">
<table width="100%">
<tr>
<?php $ind = 0; foreach( $files as $image ) { ?>
<td width="160" nowrap align="center">
<a href="javascript:switchimg( <?php echo($ind); ?> )">
<img height="100" src="scale.php?image=<?php echo($image); ?>&y=100" border="0" /
>
</a>
</td>
<?php $ind++; } ?>
</tr>
</table>
</div>
<div id="pic">
<img id="selimg" height="400" src="scale.php?image=<?php echo($files[0]);
?>&y=400" />
</div>
</body>

scale.php

<?php

$image = $_GET["image"];
$maxy = $_GET["y"];
$im = @imagecreatefromjpeg( "pics/".$image );
$curx = imagesx( $im );
$cury = imagesy( $im );
$ratio = $maxy / $cury;
$newx = $curx * $ratio;
$newy = $cury * $ratio;
$oim = imagecreatetruecolor( $newx, $newy );
imageantialias( $oim, true );
imagecopyresized( $oim, $im, 0, 0, 0, 0,
$newx, $newy, $curx, $cury );
header( "content-type: image/jpeg" );
imagejpeg( $oim );
?>
nezabor
На сайте с 19.07.2010
Offline
152
#1

отредактируйте топик, чтобы было только в CODE а не PHP

иначе трудновато с чтением

Чудес не бывает...
P
На сайте с 11.02.2018
Offline
8
#2

не понял вас

WebAlt
На сайте с 02.12.2007
Offline
262
#3

P
На сайте с 11.02.2018
Offline
8
#4

index.php

<?php
$dh = new DirectoryIterator( "pics" );

$files = array( );
foreach( $dh as $file )
{
if ( preg_match( "/[.]jpg$/", $file ) ) $files []= "$file";
}
?>
<html>
<head>
<title>Slideshow</title>
<style>
body { background: black; }
#thumbnails { height: 140px; width: 100%; overflow: auto; }
#pic { text-align: center; height: 400px; padding: 20px; }
</style>
<script>
var image_list = [ <?php $first = true; foreach( $files as $image ) { ?>
<?php echo( $first ? "" : ", " ); ?>"<?php echo( $image ); ?>"
<?php $first = false; } ?>
];

var curimage = 0;

function switchimg( ind )
{
var image = image_list[ind];
var obj = document.getElementById( "selimg" );
obj.src = "scale.php?image="+image+"&y=400";
curimage = ind;
}

function nextimage( )
{
curimage++;
if ( curimage >= image_list.length ) curimage = 0;
switchimg( curimage );
}
window.setInterval( "nextimage( )", 2000 );
</script>
</head>
<body>
<div id="thumbnails">
<table width="100%">
<tr>
<?php $ind = 0; foreach( $files as $image ) { ?>
<td width="160" nowrap align="center">
<a href="javascript:switchimg( <?php echo($ind); ?> )">
<img height="100" src="scale.php?image=<?php echo($image); ?>&y=100" border="0" /
>
</a>
</td>
<?php $ind++; } ?>
</tr>
</table>
</div>
<div id="pic">
<img id="selimg" height="400" src="scale.php?image=<?php echo($files[0]);
?>&y=400" />
</div>
</body>

scale.php

<?php
$image = $_GET["image"];
$maxy = $_GET["y"];
$im = @imagecreatefromjpeg( "pics/".$image );
$curx = imagesx( $im );
$cury = imagesy( $im );
$ratio = $maxy / $cury;
$newx = $curx * $ratio;
$newy = $cury * $ratio;
$oim = imagecreatetruecolor( $newx, $newy );
imageantialias( $oim, true );
imagecopyresized( $oim, $im, 0, 0, 0, 0,
$newx, $newy, $curx, $cury );
header( "content-type: image/jpeg" );
imagejpeg( $oim );
?>

Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct(pics,pics): �� ������ ����� �������� ����. (code: 2) in E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php:2 Stack trace: #0 E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php(2): DirectoryIterator->__construct('pics') #1 {main} thrown in E:\OpenServer\domains\php\Code\Глава 3. DHTML\Трюк 21. Создание просмотрщика слайдов при помощи DHTML\index.php on line 2

---------- Добавлено 11.04.2018 в 14:53 ----------

а разница какая

сделал как просили

ДП
На сайте с 23.11.2009
Offline
203
#5

Путь найти не может - http://php.net/manual/ru/directoryiterator.construct.php#refsect1-directoryiterator.construct-errors

Советую где-нибудь почитать про пути - относительный, абсолютные и т.п., про константу __DIR__ - жить сразу станет легче.

P
На сайте с 11.02.2018
Offline
8
#6

а что мне сделать с путем

ДП
На сайте с 23.11.2009
Offline
203
#7

Почитать, напимер, http://phpfaq.ru/newbie/paths и указать правильный путь

P
На сайте с 11.02.2018
Offline
8
#8

в чем проблема

S
На сайте с 30.09.2016
Offline
469
#9
Phpi:
в чем проблема

Проблемы как минимум две. Проблема номер раз - ты не хочешь думать, проблема номер два - скорее всего, нет такого каталога "pics".

Отпилю лишнее, прикручу нужное, выправлю кривое. Вытравлю вредителей.
P
На сайте с 11.02.2018
Offline
8
#10

а что делать

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий