如何上传&用所需的名称保存文件 [英] How to upload & Save Files with Desired name
本文介绍了如何上传&用所需的名称保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< form action =''method = 'POST'enctype ='multipart / form-data'>
< input type ='file'name ='userFile'>< br>
< input type ='submit'name ='upload_btn'value ='upload'>
< / form>
<?php
$ target_Path =images /;
$ target_Path = $ target_Path.basename($ _FILES ['userFile'] ['name']);
move_uploaded_file($ _FILES ['userFile'] ['tmp_name'],$ target_Path);
?>
当文件(图像)保存在指定的路径时...如果我想保存一些想要的名字的文件....
我已经试过取代这个
$ target_Path = $ target_Path.basename($ _FILES ['userFile'] ['name']);
用这个
$ target_Path = $ target_Path.basename(myFile.png);
但它不工作
解决方案
您可以试试这个,
$ p $ $ c $ pathinfo($ _ FILES ['userFile'] [ '名称']);
$ ext = $ info ['extension']; //获取文件的扩展名
$ newname =newname。。$ ext;
$ target ='images /'.$ newname;
move_uploaded_file($ _FILES ['userFile'] ['tmp_name'],$ target);
i am using this code to upload files(images to a folder)
<form action='' method='POST' enctype='multipart/form-data'>
<input type='file' name='userFile'><br>
<input type='submit' name='upload_btn' value='upload'>
</form>
<?php
$target_Path = "images/";
$target_Path = $target_Path.basename( $_FILES['userFile']['name'] );
move_uploaded_file( $_FILES['userFile']['tmp_name'], $target_Path );
?>
when the file(image) is saved at the specified path... WHAT if i want to save the file with some desired name....
i have tried replacing THIS
$target_Path = $target_Path.basename( $_FILES['userFile']['name'] );
WITH THIS
$target_Path = $target_Path.basename( "myFile.png" );
BUT it's not working
解决方案
You can try this,
$info = pathinfo($_FILES['userFile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "newname.".$ext;
$target = 'images/'.$newname;
move_uploaded_file( $_FILES['userFile']['tmp_name'], $target);
这篇关于如何上传&用所需的名称保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文