PHP上传图片名称 [英] PHP upload image name
本文介绍了PHP上传图片名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个PHP代码,将文件名上传到数据库。我希望能够首先上传文件名。因此,稍后我可以查找其名称并调出文件。到目前为止,这就是我拥有的
HTML代码:
I want to write a php code that uploads a file name to a database. I want to be able to first just upload the file name. So later i can look up its name and bring up the file. This is what i have so far HTML code :
<html>
<form method="post" action="image_record.php" enctype="multipart/form-data">
<p>
Please Enter the Member Name.
</p>
<p>
Member or Affiliates Name:
</p>
<input type="text" name="nameMember"/>
<p>
Upload File
<input type="file" name="file"><br><br>
</p>
<p>
<input type="submit" name="submit" value="Submit" />
</p>
<br/>
</form>
</html>
<html>
<head>
</head>
<body>
<?php
$name = $_POST["nameMember"];
$con = mysql_connect("localhost","root","password");
if (!$con) {
die("can not connect: " . mysql_error());
}
mysql_select_db("snippets",$con);
if(isset($_POST['submit']))
{
$file_name = $_FILES["file"]["name"];
//echo $file_name
$query="INSERT INTO value (file) VALUES ('".$file_name."')";
}
mysql_query($query,$con);
mysql_close($con);
?>
</body>
</head>
</html>
确定,因此它将文件上传到myphp admin,而不是文件名。很好,但是如何从php代码中调用文件名?
ok so it uploads the file to myphp admin, but not the file name. That is fine, but how do i call the file name from a php code?
推荐答案
使用已弃用mysql_ 函数
在 image_record.php
if(isset($_POST['submit']))
{
$file_name = $_FILES["file"]["name"];}
//echo $file_name
$query="insert into your_table_name (column_name) values('".$file_name."')";
$res=mysql_query($sql,$query);
}
这篇关于PHP上传图片名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文