2016-08-03 57 views
1

我的形式看起來像這樣如何通過相同的形式PHP

<form action='uploadFile.php' method='POST'> 

        <p>select an image</p> 
        <p style='font-size: 10px'>280x280px</p> 
        <input type='file' name='imageFile' /> 


        <p>select it</p> 
        <input type='file' name='uploadFile'/> 
        <p>title it</p> 
        <input type='text' id='post-title' name='title'/> 
        <p>tag it</p> 
        <input type='text' id='post-tags' name='tags'/><br /> 
        <button id='submit-file'>submit it</button> 

</form> 

php的後端上傳2個不同的文件類型看起來像

if(isset($_FILES['uploadFile']['tmp_name'])) 
{ 
if(isset($_FILES['uploadFile']['size'])) 
{ 

if(isset($_FILES['imageFile']['size'])) 
{ 
if(isset($_FILES['imageFile']['tmp_name'])) 
{ 

基本上長故事短片;在提交else語句到if(isset($ _ FILES ['uploadFile'] ['tmp_name']))並且如果(isset($ _ FILES ['imageFile'] ['size'])被觸發(通過回聲語句確認)兩者無論哪個提交。什麼會導致此任何想法?

+1

不要忘了''

的'ENCTYPE = 「的multipart/form-data的」'屬性 – Ghost

+1

爲什麼不使用多文件上傳 –

+0

@Kris Roofe;用戶需要爲每種上傳類型指定文件類型;我看到循環中的各種帖子,這就是爲什麼我想要走這條路;似乎循環的上傳是用戶必須按shift並選擇對用戶來說似乎不是公平的事情的倍數。 –

回答

1

HTML表單標籤必須包含ENCTYPE =「的multipart/form-data的」上傳文件。

1

你已經在你的代碼錯過ENCTYPE它要求ENCTYPE =「的multipart/form-data的」上傳文件

<form action="uploadFile.php" method="POST" enctype="multipart/form-data"> 

以下PHP有助於找到文件是否被上傳或不給出:

// For imageFile 
if (isset($_FILES['imageFile']) && $_FILES['imageFile']['size'] != 0) { 
    // input file selected for upload) 
} else { 
    // input file not selected for upload 
} 

// For uploadFile 
if (isset($_FILES['uploadFile']) && $_FILES['uploadFile']['size'] != 0) { 
    // input file selected for upload) 
} else { 
    // input file not selected for upload 
}