【问题标题】:I have a file upload system that renames the file and gives you the link for your file, but will not give file link我有一个文件上传系统,可以重命名文件并为您提供文件的链接,但不会提供文件链接
【发布时间】:2014-04-25 04:57:37
【问题描述】:

我有一个文件上传系统,它可以重命名文件并为您提供文件链接,但不会提供正确的文件链接,它只会给您上传文件的名称,而不是 PHP 命名它的名称。

这里是live link

这是我的代码:

<?php
$fileName = $_FILES["file1"]["name"];
$path_part = pathinfo($fileName);
$fileName = uniqid(md5_file($fileName)).".".$path_part['extension'];

$fileTmpLoc = $_FILES["file1"]["tmp_name"]; 
$fileType = $_FILES["file1"]["type"];
$fileSize = $_FILES["file1"]["size"];
$fileErrorMsg = $_FILES["file1"]["error"];
if (!$fileTmpLoc) {
    echo "ERROR: Please browse for a file before clicking the upload button.";
    exit();
}

if(file_exists('uploads/' . $_FILES['file1']['name'])){
    die('File with that name already exists.');
}

if(move_uploaded_file($fileTmpLoc, "uploads/$fileName")){

 echo "Your File Link<input value='http://testserver1234.no-ip.org/Upload-System/uploads/".  basename( $_FILES['file1']['name']).
    "' style='width: 100%'>";

} else {
    echo "move_uploaded_file function failed";
}
?>

我犯了什么错误。我该如何纠正它?

【问题讨论】:

    标签: php file hyperlink upload rename


    【解决方案1】:

    这个uploads/$fileName是需要返回的新文件,而你正在使用basename($_FILES['file1']['name']

    替换

    echo "Your File Link<input value='http://testserver1234.no-ip.org/Upload-System/uploads/".  basename( $_FILES['file1']['name']).
    "' style='width: 100%'>";
    

     echo "Your File Link<input value='http://testserver1234.no-ip.org/Upload-System/uploads/".  $fileName .
    "' style='width: 100%'>";
    

    【讨论】:

      猜你喜欢
      • 2014-06-22
      • 2013-08-22
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2019-06-18
      • 1970-01-01
      相关资源
      最近更新 更多