After I write the following -6ren">
gpt4 book ai didi

php - Move_uploaded_file() 函数显示错误

转载 作者:行者123 更新时间:2023-11-28 23:16:58 25 4
gpt4 key购买 nike

我正在尝试动态上传图片。 HTML 代码是:

<form method="post" action="" name="form1" id="form1" enctype="multipart/form-data">
<label for "file">Select Picture</label><br>
<input type="file" name="file" id="file"><br>
<input type="hidden" value="<?php echo $_POST['pic'];?>" name="pic">
<input type="submit" value="Upload" name="upload" id="upload"><br>
</form>

After I write the following code it is showing me the error: " move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory " and "Unable to move 'C:\xampp\tmp\phpB67C.tmp' to 'images/' ". The php code for this is:

if(isset($_POST['upload'])){
$pic=$_POST['pic'];
move_uploaded_file($_FILES["file"]["tmp_name"], "images/".$pic); //."jpg");
}

请告诉我如何消除错误并能够添加和查看图片。

最佳答案

Change Like This

您可以使用 $_FILES["file"]["name"] 变量获取文件名。因此,如果有任何文件上传,您必须使用此方法获取文件名,而不是使用 $_POST

if(isset($_POST['upload']))
{
$pic=$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "images/".$pic); //."jpg");
}

关于php - Move_uploaded_file() 函数显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43448030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com