donglusou3335 2015-09-26 09:39
浏览 13
已采纳

在PHP中将文本附加到文件名? [关闭]

Hello: I am relatively new to PHP. I have a directory with 16 .jpg files in it. (eg: /images/boxer1.jpg, boxer2.jpg etc...)

As part of a larger PHP file copy and upload procedure, I want to create a second version of these files by appending a _h to the file (eg: boxer1_h.jpg, boxer2_h.jpg, etc..); leaving the new files in the same directory with the original files for further manipulation.

What would be the easiest way to accomplish this using PHP programming?

  • 写回答

2条回答 默认 最新

  • dsvyc66464 2015-09-26 09:53
    关注

    Mureinik's answer is a good solution, it copies the uploaded file and changes it's name. Here is a good way to do it during the upload.

    You used

    move_uploaded_file ($uploaded, 'path/to/uploads/'.$filename);
    

    Use it again:

    move_uploaded_file ($uploaded, 'path/to/uploads/'.$str_replace('.', '_h.', $filename));
    

    AND THAT, assuming you give a proper filename to the uploaded files without any other DOTS besides the one to separate the extension from the name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部