2017-03-15 10 views
-2

업로드 한 이미지를 파일에 업로드 한 다음 페이지에 표시 할 수있는 코드가 있습니다. 유일한 문제는 이미지가 표시되지 않는다는 것입니다. 여기 파일에 업로드 된 이미지를 표시하는 PHP

<?php 
$target_dir = "uploads/"; 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
//echo $target_file; 
$uploadOk = 1; 
//$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 




// Check if file already exists 
if (file_exists($target_file)) { 
    echo "Sorry, file already exists."; 
    $uploadOk = 0; 
} 






// Check file size 
if ($_FILES["fileToUpload"]["size"] > 700000000) { 
    echo "Sorry, your file is too large."; 
    $uploadOk = 0; 
} 





// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
    echo "Sorry, your file was not uploaded."; 
// if everything is ok, try to upload file 
} else { 




    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
     echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
    } else { 
     echo "Sorry, there was an error uploading your file."; 
    } 
} 



/* Displaying Image*/ 
//$image=$_FILES["fileToUpload"]["name"]; 
//  $img="uploads/".$image; 

echo "<br>"; 

         //echo'<br><img src="'.$img.'">'; 
         //echo "<br><img src=\"upload/$img\">"; 


echo '<br><img src="$target_file">'; 

내가 이미지가 표시되고있는 부분이다 :

/* Displaying Image*/ 

    echo "<br>"; 

    echo '<br><img src="$target_file">'; 
+0

이 우리에게 , 'echo'는 무엇입니까
'; 너 보여? 그리고 주석 처리 된 다른 사람들을 위해서? –

+0

파일이 아닌 디렉토리에 업로드됩니다! ;) 이미지, 단어 문서, csv, pdf ... 모든 파일입니다. 따라서 이미지를 파일로 업로드하거나, 이미지를 디렉토리로 업로드하거나, 모든 문서의 경우 파일을 디렉토리에 업로드 할 수 있습니다. 그냥 다음 번에;) – Twinfriends

답변

1

보십시오 : 당신은 HTML 소스를 볼 때

echo '<br><img src="'.$target_file.'">'; 

또는

echo "<br><img src='$target_file'>"; 
+0

감사합니다! 첫 번째 코드는 나를 위해 작동합니다. – Smeaj