2017-04-04 28 views
-2

嘿,我使用PhoneGap來製作一個應用程序,用戶可以點擊一個img,然後從那裏選擇一個img來代替使用電話,這對於佈局非常重要這只是你可以看到並點擊的圖片。我如何讓用戶上傳和使用圖片

是否有可能在javascript/html中做到這一點?請幫助我100%失去。

+0

歡迎來到SO請參考[幫助中心](http://stackoverflow.com/help)查看[如何提出一個好問題](http://stackoverflow.com/help/how-問)以及本網站的[主題](http://stackoverflow.com/help/on-topic)是什麼類型的問題。 – Pete

+0

下次我有空時,我會這樣做。但是,你能問我(幫助)我的問題嗎? –

+0

不,因爲它是關閉主題 – Pete

回答

1

可以使用HTML將文件上傳到Web服務器。您還需要PHP來處理並將上傳的文件移動到所需的目的地。應該在上傳的圖像文件上進行許多驗證檢查,以防止任何漏洞。對於這個PHP是必需的。沒有適當的驗證,這對您的應用/服務器是一種安全風險。

如:

HTML代碼(的index.html):

<!DOCTYPE html> 
<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
    Select image to upload: 
    <input type="file" name="fileToUpload" id="fileToUpload"> 
    <input type="submit" value="Upload Image" name="submit"> 
</form> 

</body> 
</html> 

PHP代碼(upload.php的):

<?php 
    $target_dir = "uploads/"; 
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
    $uploadOk = 1; 
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
    // Check if image file is a actual image or fake image 
    if(isset($_POST["submit"])) { 
     $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
    if($check !== false) { 
      echo "File is an image - " . $check["mime"] . "."; 
      $uploadOk = 1; 
     } else { 
      echo "File is not an image."; 
      $uploadOk = 0; 
     } 
    } 
?> 

要更多地瞭解和上傳處理文件, W3Schools

希望這對你有所幫助。隨時尋求任何幫助。

+0

當我選擇了我的img並點擊上傳網站 - img未找到或可能已經刪除。即使我沒有觸及它。它對我所有的img都是如此。 你也知道一種方式,在屏幕上不會出現按鈕,它只是一個img你點擊上傳新的imgs在它的地方。 –