php文件上传大写文件名问题

编程入门 行业动态 更新时间:2024-10-10 09:19:29
本文介绍了php文件上传大写文件名问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个非常标准的文件上传表单(也正在写入 mysql 数据库).它在我的整个测试过程中都运行良好,然后我去测试了一个以全部大写字母命名的文件.该文件不会上传.我想出一个简单的解决方案,只需在上传前使用strtolower"重命名文件,但没有运气.也试过strtoupper,仍然没有运气.我想我也遇到了以数字开头的文件的问题.(我仔细检查了一下,是的,该文件夹是可写的.)

I have a pretty standard file upload form (that is also writing to a mysql db). It was working fine throughout my testing, then I went and tested a file that was named with all capital letters. The file would not upload. Simple solution I figured, just rename the file before the upload with 'strtolower' but no luck. Also tried strtoupper, still no luck. I think I'm also running into this issue with files starting with numbers. (i did double check and yes the folder is writable.)

$upload_dir = "/path/to/the/upload/folder/entries/";
$new_filename = mysql_insert_id()."_".$filename;
$tmp_name = $_FILES["filename"]["tmp_name"];
move_uploaded_file($tmp_name, $upload_dir . $new_filename);

非常感谢任何帮助.

推荐答案

需要隔离发生错误的步骤——具体是什么意思,文件不会上传"?没有文件到达服务器?重命名不起作用吗?执行插入操作的 mysql 语句格式不正确吗?如果文件永远不会到达服务器,那么您就没有任何东西可以调用 strtolower.

Need to isolate the step where the error is happening--what do you mean specifically, "the file will not upload"? Does no file get to the server? Does the rename not work? Is the mysql statement doing the insert not formed correctly? If the file never gets to the server, then you have nothing on which to invoke strtolower.

取一个已知的、可以工作的、可上传的文件,上传它以确保它可以工作,然后将其重命名为大写版本,然后重试.如果 picture.jpg 有效,那么 PICTURE.JPG 是否有效?还是PICTURE.jpg?我想知道您的代码的前面部分是否有某些内容决定.JPG"(或任何大写扩展名)不是像.jpg"这样的有效上传.

Take a known, working, uploadable file, upload it to be sure it works, then rename it to its uppercase version and try again. If picture.jpg works, does PICTURE.JPG? Or PICTURE.jpg? I'm wondering if there's something in the previous parts of your code that is deciding ".JPG" (or whatever capitalized extension) isn't a valid upload like ".jpg" is.

这篇关于php文件上传大写文件名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 15:12:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1174843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   文件上传   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!