Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php new Imagick()不接受特定数组_Php_Arrays_Imagick - Fatal编程技术网

Php new Imagick()不接受特定数组

Php new Imagick()不接受特定数组,php,arrays,imagick,Php,Arrays,Imagick,我正在尝试创建Imagick的新实例: $original = new Imagick($array); 我在两个不同的例子中这样做。一种方法总是有效,另一种方法总是失败,但它们使用相同的精确数组数组并不总是相同的,但为了便于解释,我展示了一个恰好使用相同数组的示例。以下是每个阵列的var_转储: 工作阵列: array(3) { [0]=> string(20) "image_files/bbb0.jpg" [1]=> string(20) "image_files/bb

我正在尝试创建Imagick的新实例:

  $original = new Imagick($array);
我在两个不同的例子中这样做。一种方法总是有效,另一种方法总是失败,但它们使用相同的精确数组数组并不总是相同的,但为了便于解释,我展示了一个恰好使用相同数组的示例。以下是每个阵列的var_转储:

工作阵列:

  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" } 
失败的阵列:

  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);
我没有看到的第二个数组有什么不同吗

编辑:以下是构造失败阵列的代码:

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

问题在于PHP文件的目录结构

正在从基目录创建工作数组。 正在从名为actions的目录创建失败的数组


不管您运行的脚本存在于何处,重要的是加载了什么脚本,即它是通过include或require从根目录加载的吗?或者直接称为www.example.com/scripts/script.php。这将决定如何构造到其他文件的路径。

数组是相同的。没有特殊的隐藏字符,什么都没有。是的,它们是,这就是为什么我会对它发疯。你需要提供更多的上下文,显然不是数组的错。你有例外吗?调用此的脚本是否在同一目录中?在第二次调用之前是否执行了任何chdir或其他操作?是否可以验证第二次调用时文件是否确实存在,请在数组中的每个项上使用file\u。使用dirname\u file\u/some/path/file.ext”,您将始终从当前文件目录开始。不管文件本身是包含还是直接运行。