我自己创建了这个脚本,一旦我实际上传文件就会查看安全性,但目前我收到以下错误:
警告:move_uploaded_file(public_html / uploads / rikkles / 1 / apt& c-application-
form-2005.pdf)[function.move-uploaded-file]:无法打开流:没有这样的文件或 目录在/websites/123reg/LinuxPackage22/sf/pa/ys/sfpayslips.info/public_html/login 第16行的/upload.php
错误:
警告:move_uploaded_file()[function.move-uploaded-file]:无法移动 '/ tmp / phpz4zlrR'到'public_html / uploads / rikkles / 1 / apt& c-application-form-2005.pdf'in /websites/123reg/LinuxPackage22/sf/pa/ys/sfpayslips.info/public_html/login/upload.php 第16行
以下是代码:
if($_POST["upload"]){
$target_path = 'public_html/uploads/' . strtolower(str_replace(' ','',$_POST["username"])) . '/' . $_POST["month"] . '/' . basename($_FILES['uploadedfile']['name']);
$filename = basename($_FILES['uploadedfile']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "pdf") && ($_FILES["uploadedfile"]["type"] == "application/pdf") && ($_FILES["uploadedfile"]["size"] < 550000)) {
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "<div class='success'>The file " . "<span class='filename'>" . basename( $_FILES['uploadedfile']['name']) . "</span>" . " has been uploaded</div>";
} else {
echo "<div class='error'>There was an error uploading the file, please try again!</div>";
}
} else {
echo "<div class='error'>You can only upload PDF file types</div>";
}
print $target_path;
}
答案 0 :(得分:0)
谢谢大家,这是一个路径问题,出于安全原因,文件被上传到应用程序文件夹之外,所以我使用$ _SERVER [“DOCUMENT_ROOT”]来获取ABSPATH。