简体   繁体   中英

I have a file upload system that renames the file and gives you the link for your file, but will not give file link

I have a file upload system that renames the file and gives you the file link, but will not give the right file link, it will just give you the name of the file you uploaded not what PHP named it.

Here is the live link

Here is my Code :

<?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";
}
?>

What is the mistake I have done. And How can I correct it?

This uploads/$fileName is the new file that needs to be returned, while you are using basename( $_FILES['file1']['name']

Replace

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

With

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM