Dinamik oluşturulan dosya yükleme kontrolü

2 Cevap php

Hai I am having a form which contains a filetype like this

  <tr><td> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td></tr>

submit i bir script arıyorum

function addRowToTable()
    {
        var tbl = document.getElementById('uploadTab');
        var lastrow = tbl.rows.length;
        var iteration = lastrow; 
        var row = tbl.insertRow(lastrow);

        var cell2 = row.insertCell(0);
        var e2 = document.createElement('input');
        e2.type = 'file';
        e2.name = 'ufile[]';
        e2.id = 'ufile[]';
        e2.size='50';
        cell2.appendChild(e2);
    }

Bu script bir düğme tıklama tr üretir ... benim görüşüm generatedsource aracında i "" böyle olsun

<tr><td><input size="50" id="ufile[]" name="ufile[]" type="file"></td></tr>

when i submit the form i dont get the file name for the generated file type in my view page But i get the file name foe the one that is default What may be the problem?

Bu sayfada benim formu gönderme,

<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];
$path4= "upload/".$HTTP_POST_FILES['ufile']['name'][3];

//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
echo copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";

///////////////////////////////////////////////////////

// Use this code to display the error or success.

$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];

if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}

else {
echo "ERROR.....";
}

//////////////////////////////////////////////

// What files that have a problem? (if found)

if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}

if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}

if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}

?>

edit This is my array

Array ( [ufile] => Array ( [name] => Array ( [0] => stripe.jpg [1] => stripe.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => D:\xampp\tmp\php29A9.tmp [1] => D:\xampp\tmp\php29AA.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 8717 [1] => 8717 ) ) ) 

2 Cevap

Kullanım Firebug'ın sağ tıklayın> yeni girdi aslında formun bir çocuk olduğundan emin olmak için "Eleman kontrol edin". Aksi takdirde, birlikte gönderdi olmayacaktır.

Söylemek istemiyorum, ama enctype niteliğini dahil hatırladım?

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

Bu olmadan, bir dosya yükleme olsun asla; Sadece sunulan değer olarak dosya görürsünüz.

<input name="ufile[]" type="file" id="ufile[]" size="50" />

Bir id köşeli parantez eklemek geçersiz bulunuyor. Sadece alphanumerics artı .-_ içerir ve bir mektup ile başlar, bir id seçin. Her oluşturulan elemana bir id eklemeniz gerekiyorsa, her zaman farklı olduğundan emin olun. Bildiğim kadarıyla gördüğünüz gibi aslında bu kimlikleri herhangi birini kullanarak, öyle değil mi rağmen oldukça kolay hepsini ihmal olabilir.

$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];

EXTREME TEHLİKE. Kullanıcı .. (bir dizin yukarı gitmek dahil) ve .php gibi aktif filetypes, dosya şey koyabilirsiniz. Lütfen sunucunun dosya sistemi üzerinde kullanıcı gönderilen dosya adlarını asla güvenme! Şiddetle (düşündüğünüzden daha zor olan) onları sterilize ya da daha iyi, altında saklamak için tamamen ilgisiz adı kullanın.

Kullanıcılar hiç dosya yüklemek için izin büyük riskler taşır. this question daha fazla tartışma için bkz.

echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";

HTML bir metin dizgisi koymak bu ve her zaman, bunu htmlspecialchars() aramak gerekir. Aksi < ve dize & karakter komut dosyası içeren biçimlendirme içerebilir, ve çapraz site betik güvenlik delik var.