我想將選定的圖像文件複製到另一個文件夾。圖像選擇過程是動態的。我使用下面的PHP代碼進行復制過程。未能打開流:沒有這樣的文件或目錄
//$cnt is count of selected images
for($i=0;$i<$cnt;$i++)
{
$img = $sel['album_images']; //name of file to be copied
//read the file
$fp = fopen('uploads/members/album/'.$_SESSION['ses_userid'].'/'.$img, 'r') or die("Could not contact $img");
$page_contents = "";
while ($new_text = fread($fp, 100))
{
$page_contents .= $new_text;
}
chdir("uploads/products/design/"); //This moves you from the current directory user to the images directory in the new user's directory
$newfile = "product-".strtotime('now').".png"; //name of your new file
//create new file and write what you read from old file into it
$fd = fopen($newfile, 'w');
fwrite($fd, $page_contents);
fclose ($fd);
}
上面的代碼是完全運行,如果所選擇的圖像數爲1.but它產生錯誤,如果所選擇的圖像數大於1
Error is :
Warning: fopen(uploads/members/album/72/full_e5829jellyfish.jpg) [function.fopen]: failed to open stream: No such file or directory in D:\wamp\www\myprint\photoprint_step2.php on line 51
Could not contact full_e5829jellyfish.jpg
注意:如果所選擇的圖像數是2,則第一張圖像將被成功複製,下一張(第二張圖像)將產生錯誤。發生了什麼?
的可能的複製[PHP - 未能打開流:沒有這樣的文件或目錄(http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) –