2012-08-14 77 views
1

我有以下腳本的表格允許文件上傳的一部分,完整的腳本在這裏:Issue with image upload php: undefined index。它工作正常,因爲它會停止腳本,如果沒有選擇文件並在表單完全填充時上傳(僅適用於登錄用戶)圖片上傳文件類型驗證使用php - pdf和jpeg

我到目前爲止沒有運氣試圖做的事情,但是隻限於只能將類型上傳到pdf和jpeg。

任何建議,歡迎

<?php   
    if (is_uploaded_file ($_FILES ['image']['tmp_name'])) { 
    if (move_uploaded_file($_FILES ['image']['tmp_name'], 
    "uploads/{$_FILES['image']['name']}")) { // Move the file over. 
    echo '<p>The file has been uploaded!</p>'; 
    } else { // Couldn't move the file over. 
    echo '<p><font color="red"> The thumbnail image could not be uploaded.</font></p>'; 
    $i = FALSE; 
    } 
    $i = $_FILES['image']['name']; 
    } else { 
    $i = FALSE; 
    } 
    ?>  

回答

3

你應該閱讀說明書$_FILE type這將是這樣的:

if ($_FILES['file']['type'] == 'image/jpeg') && ($_FILES["file"]["type"] == "application/pdf") 
+0

待辦事項你知道如何用PDF格式顯示簽名?我的iframe現在顯示PDF簽名,它正在保存但不顯示它。 – Alz 2014-11-24 05:17:12

0

這將這樣的伎倆你...

<?php 
    if(isset($_FILES['image'])&&(!empty($_FILES['image']))){ 
    if (($_FILES['image']['type']== "image/jpeg")||($_FILES['image']['type'] == "application/pdf")){ 
$filename =$_FILES['image']['name']; 
    $copy = copy($_FILES['image']['tmp_name'], "uploads/".$filename); 
    if($copy){ 
    echo '<p>The file has been uploaded!</p>'; 
    }else{ 
    echo 'File is not a jpeg or pdf'; 
    } 
    }else{ 
    echo '<p><font color="red"> The thumbnail image could not be uploaded.</font></p>'; 
    } 
    }else{ 
    echo 'no image is selected'; 
    } 
    ?> 
+0

該腳本設法驗證pdf和jpeg並將腳本上傳到正確的文件夾,但它將文件名重命名爲1.是否有任何方法保留文件名? – AdamMc 2012-08-14 06:28:05

+0

對不起,我沒有注意到。我已編輯答案..現在它可以檢查它。 – vinu 2012-08-14 06:53:29

+0

仍然沒有運氣,謝謝你嘗試 – AdamMc 2012-08-14 07:13:26