0
我有兩個名爲'avatars'和'small_avatars'的文件夾。我試圖做的是比較這些文件夾(都有圖像)的內容相互使用數組,像這樣(請參閱下面的代碼),但我不認爲它的作品。有人可以檢查並指出需要改變什麼才能使其工作?我是否需要定義保存到數組中的文件的數據類型?如何將圖像從數組複製/移動到文件夾中php
$dirBig= $root.AVATAR_DIRECTORY;
$dirSmall= $root.SMALL_AVATAR_DIRECTORY;
$imagesBig = array("image/gif","image/jpg","image/jpeg","image/png");
$imagesSmall = array("image/gif","image/jpg","image/jpeg","image/png");
// check if avatar directory exists then copy the names
// of the files to an array
if (is_dir($dirBig)){
// for debug purposes
echo ("$dirBig on dir </br></br>");
}else{
echo ("dir not found\n");
}
if ($isot=opendir($dirBig)){
while ((false !== $file = readdir($isot))):
if ($file[0] == ".")continue; {
echo ("Filename in avatars : $file </br>");
$imagesBig[]=$file;
}
endwhile;
closedir($isot);
}
// check if small avatar directory exists then copy the names
// of the files to an array
if (is_dir($dirSmall)) {
echo ("</br>".SMALL_AVATAR_DIRECTORY. " on dir </br></br>");
}else{
echo("dir not found \n");
}
if ($pienet=opendir($dirSmall)) {
while ((false !== $file = readdir($pienet))) :
if ($file[0] == ".") continue;{
echo ("Filename in small avatars: $file</br>");
$imagesSmall[] = $file;
}
endwhile;
closedir($pienet);
}
//compare the two arrays with each other
$comp_result= array_diff($imagesBig, $imagesSmall);`
從比較兩個陣列相互結果包含的不存在於「small_avatar」文件夾中的文件的名稱。這些文件名沒有擴展名,例如:「。jpg,.png等。我試圖實現的下一件事是通過嘗試以下操作將這些圖像從」$ comp_result「複製到」small_avatar「文件夾: 編輯取代前者對於這個foreach循環。現在有沒有錯誤,但圖像仍沒有從數組到該文件夾複製... :(
$a = $comp_result;
foreach ($a as $img){
if (move_uploaded_file($img, $dirSmall)){
$imagetools->resizeImage($dirSmall, NULL, NULL, NULL, THREAD_AVATAR_MAX_WIDTH, THREAD_AVATAR_MAX_HEIGHT, AVATAR_KEEP_IMAGE_ASPECT_RATIO);
}else{
echo("Copying file ".$img." failed to dir ".$dirSmall." !</br>");
}
}
但它不工作。我得到errormessages如:
- 警告:複製():文件名不能爲空
- 警告ing:複製(5006):未能打開流:文件或目錄不存在於... 而我的數組從[4]不是[0]?任何想法爲什麼發生這種情況
我真的很感激,如果有人能幫我讓這個功能工作。我一直在谷歌搜索幾天。
我試過3210,但是這並沒有給我任何值...
預先感謝您! :)
謝謝,這解決了一個'未定義的抵消',但不是全部..試圖找出我的問題.. – sumppi 2012-03-02 10:21:23