2016-04-23 76 views

回答

1

如果我明白你的問題吧,我還需要在我的項目相同的功能,這是我做的,

這是fileUpload.php文件

<?php 
$target_path="uploads/".$_POST['username']."/"; 
if (!is_dir($target_path)) 
// is_dir - tells whether the filename is a directory 
{ 
    //mkdir - tells that need to create a directory 
    mkdir($target_path); 
} 
$target_path=$target_path.basename($_FILES['image']['name']); 
try { 
    //throw exception if can't move the file 
    if (!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) { 
     throw new Exception('Could not move file'); 
    } 
    echo $target_path; 
} catch (Exception $e) { 
    die('Upload Failed: ' . $e->getMessage()); 
} 
?> 

,而這是該文件從瀏覽器中測試你的上傳,

<html> 
    <head> 
     <title>File Upload Form</title> 
    </head> 
    <body> 
     <form enctype="multipart/form-data" action="fileUpload.php" method="POST">    
      <br/>Choose a file to upload: <br/><input name="image" type="file" /><br /> 
      User Name: <input type="text" name="username"/> 
      <input type="submit" value="Upload File" /> 
     </form> 

    </body> 
</html> 

我認爲你可以很容易地找出如何從Android處理這個問題。

希望這會有所幫助! :)

+0

@Marc你應該接受的答案,如果它幫助你,如果沒有至少說明您的問題進一步的評論。 –

相關問題