2016-11-16 71 views
1

我試圖使用PHP將圖像從一個文件夾複製到另一個文件夾。 圖像移動正常,但是當我打開圖像時,圖像未顯示。從一個文件夾複製到另一個文件夾時未顯示圖像

任何想法?

謝謝。

以下是我的代碼。

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'image_copy') { 
    $image = $_POST['image']; 
    //name of file to be copied 
    $img = $image; 
    //read the file 
    $fp = fopen('files/post/' . $img, 'r') or die("Could not contact $img3"); 
    $page_contents = ""; 
    $new_text = fread($fp, 100); 
    $page_contents = $new_text; 
    //This moves you from the current directory user to the images directory in the new user's directory 
    chdir("files/profile"); 
    //name of your new file 
    $newfile = $image; 
    //create new file and write what you read from old file into it 
    $fd = fopen($newfile, 'w'); 
    fwrite($fd, $page_contents); 
    //close the file 
    fclose($fd); 
    exit; 
} 
+0

你可能會顯示''你正在使用的HTML代碼? – Abela

+0

好吧,我會@Abela – sradha

回答

0

我已用文件獲取內容並把內容的一些其他方式。

$image = $_POST['image']; 
    $dir_to_save = "files/profile/"; 
    if (!is_dir($dir_to_save)) { 
     mkdir($dir_to_save); 
    } 
    file_put_contents($dir_to_save . $image, file_get_contents('files/post/' . $image)); 

,但我無法在PHP的招法做。

+0

你是否介意刪除這個答案並編輯你的更新你的問題呢? –

相關問題