开发者

how to rename file name while uploading

I have a file with 2 input fields one for file name (user will type) and the second one for choosing file what I want to upload the file to a directory with the name user typed. down is the code I'm using guys please help me how to change the file name into what user typed.

<?php

$filename = $_POST["file"]
$upload   = $_FILES['userfile'];


$target_path = "upload/";

$target_path .= $upload["name"];

$newname = "anything";

if(move_uploaded_file($upload["tmp_name"], $target_path))
    {
        ec开发者_如何学Goho "uploaded successfully";
    }
?>


Change $target_path .= $upload["name"]; to something like $target_path .= $filename;.

edit: For the record, I have to say that letting people upload files (and choose the extension) to your web server raises some serious security concerns. I would suggest at least disabling the ability to execute scripts in your target folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜