简体   繁体   English

从文件名中删除扩展名,但保持扩展名与文件关联

[英]remove extension from filename, but keep extension associated to file

I have been having difficulty loading an .xlsx into a directory and not having .xlsx attached to the filename, but keeping it assocaited to the .xlsx file type. 我一直很难将.xlsx加载到目录中,并且没有将.xlsx附加到文件名,但是一直将其关联到.xlsx文件类型。 This is as close as I could get 这是我所能接近的

$maintenance_dir = "C:/wamp/www/mafrd/maintenance/$siteNAME/";
$maintenance_file = $maintenance_dir . basename($_FILES["loadtrip"] ["name"], ".xlsx") .'_'. date("Y-m-d");
if (!file_exists($maintenance_dir)) {
mkdir($maintenance_dir, 0777, true);
}
$uploadOk = 1;

// 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['loadtrip']['tmp_name'], $maintenance_file)) {
    echo "The file ". basename( $_FILES["loadtrip"]["name"], ".xlsx") .'_'. date("Y-m-d"). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}
}  

在此处输入图片说明

It currently comes out as the orange highlighted and I would like it to mirror the yellow. 当前它以橙色突出显示,我希望它能反映黄色。

Under Windows, the file type is associated with the filename. 在Windows下,文件类型与文件名关联。 You can't remove the .xlsx and expect it to behave as normal. 您不能删除.xlsx并期望它表现正常。

The solution I would recommend you is to add the date before the extension: 我建议您使用的解决方案是在扩展名之前添加日期:

 $maintenance_file = $maintenance_dir . basename($_FILES["loadtrip"] ["name"], ".xlsx") .'_'. date("Y-m-d") . ".xlsx";

If this is not what you're looking for, you could create a different extension and map it to Excel. 如果这不是您想要的内容,则可以创建其他扩展名并将其映射到Excel。

You can still open the file with Excel even if it has a different extension, but it may not open automatically when clicking on the item. 即使扩展名不同,您仍然可以使用Excel打开该文件,但是单击该项目时它可能不会自动打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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