【发布时间】:2023-03-19 21:46:01
【问题描述】:
我刚刚创建了上传脚本,但上传文件后出现问题
我可以这样看他们:
打开文件号 1 后文件完美打开,但问题是当我触摸文件 2 时 因为这个文件名字里有空格或者特殊符号,打开是这样的
这是我的 php 文件
<?php
$target_dir = "uploads/up/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has
been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
显示.php
<?php
$sub = ($_GET['dir']);
$path = 'up';
$path = $path . "$sub";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
if($file != "." && $file != "..") {
if (substr($file, -4, -3) =="."){
echo "<a href='".htmlspecialchars($path$result)."'>".$file."</a><br>";
}
$i++;
}
}
closedir($dh);
?>
【问题讨论】:
-
如果你需要帮助,你需要把你的代码放在这里。
-
请以文本形式发布代码
-
urlencode()是要走的路!如果名称中有空格