1

Imagickの新しいインスタンスを作成しようとしています:

  $original = new Imagick($array);

私はこれを2つの異なるインスタンスで行います。一方の方法は常に機能し、もう一方の方法は常に失敗しますが、同じ正確な配列を使用します(配列は常に同一であるとは限りませんが、説明を簡単にするために、同じ配列を使用する例を示しています)。var_dump各配列のは次のとおりです。

ワーキングアレイ:

  array(3) { [0]=> string(20) "image_files/bbb0.jpg" [1]=> string(20) "image_files/bbb1.jpg" [2]=> string(20) "image_files/bbb2.jpg" } 

失敗したアレイ:

  array(3) { [0]=> string(20) "image_files/bbb0.jpg" [1]=> string(20) "image_files/bbb1.jpg" [2]=> string(20) "image_files/bbb2.jpg" } 

ご覧のとおり、これらは同一ですが、なぜ私のPHPは

$new = new Imagick($array);

私が見ていない2番目の配列について何か違うことがありますか?

編集:失敗している配列を構築するコードは次のとおりです。

$n = $_GET["n"];
$city = preg_replace("/[0-9]/", "", $n);
$num = preg_replace("/".$city."/","",$n);

// create an array to hold directory list
$results = array();
// create a handler for the directory
$directory = '../image_files';
$handler = opendir($directory);

while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..") {
    // check with regex that the file format is what we're expecting and not something else
    if (preg_match("/^".$city."[1-9][0-9]\.jpg$/i",$file)) {
    if (preg_match("/^".$city.$num."\.jpg$/i",$file)) { 
        unlink("../image_files/".$file);
    } else {
        $results[] = "../image_files/" . $file;
    }
    } else if (preg_match("/^".$city."[0-9]\.jpg$/i",$file)) {
    if (preg_match("/^".$city.$num."\.jpg$/i",$file)) { 
        unlink("../image_files/".$file);
    } else {
        $results[] = "../image_files/" . $file;
    }
    } 
    }
}

sort($results);

$i = 0;
$newResults = array();
foreach( $results as $key => $value ) {
$old = $value;
//echo "old: " . $old . " ";
if (preg_match("/[1-9][0-9]/",$value)) {
    $newstr = preg_replace("/[1-9][0-9]/", $i."temp", $value);
} else if (preg_match("/[0-9]/",$value)) {
    $newstr = preg_replace("/[0-9]/", $i."temp", $value);
}

$newResults[] = $newstr;
//echo "new: " . $newstr . "<br>";
rename($old,$newstr);
    $i++;
}

// create an array to hold directory list
$results = array();
// create a handler for the directory
$directory = '../image_files';
$handler = opendir($directory);

while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..") {
    $old = $file;
    $new = preg_replace("/temp/", "", $file);
        rename("../image_files/".$old,"../image_files/".$new);
    }
}

$finalResults = array();

foreach( $newResults as $key => $value ) {
    $newstr = str_replace("../", "", $value);
    $newstr = str_replace("temp","",$newstr);
    $finalResults[] = $newstr; 
}

sort($finalResults);

createMontage($finalResults,"-a",$city);
4

1 に答える 1

0

問題は、PHP ファイルのディレクトリ構造にありました。

「作業配列」は、ベース ディレクトリから作成されています。「失敗したアレイ」は、という名前のディレクトリから作成されていactionsます。

実行しているスクリプトがどこに存在するかは問題ではありません。そのスクリプトをロードしたものが重要です (つまり、 or を介してルートディレクトリからロードされましたincluderequire? または直接呼び出されましたwww.example.com/scripts/script.php)。これにより、他のファイルへのパスを構築する方法が決まります。

于 2013-02-13T18:05:11.223 に答える