使用同一函数php上载两次时出现问题
我的网站的文件上传脚本有问题。我复制了一个简单的上传脚本,我正在设置它,以便可以上传多个文件。为此,我必须先为一个文件制作一份表格,然后为下一个文件制作一份表格副本。(我先用表单中的“multiple”标记设置页面,但后来我发现工作的IE是版本8,没有flash。所以我必须这样做) 脚本上传正常。问题是第二个文件名为file1.jpgfile2.jpg,第三个文件名为file1.jpgfile2.jpgfile3.jpg,依此类推 这是我的表单,后面是带有表单#2 File#2的代码,然后是相同的表单:使用同一函数php上载两次时出现问题,php,unset,Php,Unset,我的网站的文件上传脚本有问题。我复制了一个简单的上传脚本,我正在设置它,以便可以上传多个文件。为此,我必须先为一个文件制作一份表格,然后为下一个文件制作一份表格副本。(我先用表单中的“multiple”标记设置页面,但后来我发现工作的IE是版本8,没有flash。所以我必须这样做) 脚本上传正常。问题是第二个文件名为file1.jpgfile2.jpg,第三个文件名为file1.jpgfile2.jpgfile3.jpg,依此类推 这是我的表单,后面是带有表单#2 File#2的代码,然后是相同
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=addpicturetoproc">
<input type="hidden" name="uploadpath" value="<? echo "Prosedyrer/$hovedkategori/$underkategori/$navn/$mappe_navn/" ?>">
Bildefil: <input type="file" name="fileup" value=""><br>
<input type="submit" name="submit" value="Upload">
</form>
<br>
<?
}
elseif ($choice=="addpicturetoproc")
{
$max_size = 2000; // maximum file size, in KiloBytes
$alwidth = 1900; // maximum allowed width, in pixels
$alheight = 1800; // maximum allowed height, in pixels
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo '<h1>Filen: <b>'. basename( $_FILES['fileup']['name']). '</b> ble lastet opp!</h1>';
}
else echo '<b>Feil ved opplastning.</b>';
}
else echo $err;
}
?><p>Do you need another upload?</p>
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=addpicturetoproc">
<input type="hidden" name="uploadpath" value="<? echo $uploadpath; ?>">
Bildefil: <input type="file" name="fileup" value="Sett inn bildefilen her"><br>
<input type="submit" name="submit" value="Last opp bildefil">
</form>
<br>
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=menu">
<input type="submit" name="submit" value="Nei, jeg er ferdig">
</form>
我相信这是因为您将附加到$uploadpath
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
因此,第一个文件将是file1.jpg
,然后第二个文件将是file1.jpgfile2.jpg
,依此类推
我建议将基本上传路径设置为另一个变量,并尝试以下操作
$uploadpath = $baseuploadpath . basename( $_FILES['fileup']['name']);
为什么在第二个表单中使用$uploadpath
var?