这是我从谷歌搜索得到的代码。但我不知道那将是img.php。我在谷歌搜索但无法解决此问题。
HTML:
< form action =" img.php " method = "POST" enctype = "multipart/form-data">
< input type="file" name = "myfile" />
< input type = "submit" value="upload" />
< /form>
PHP:
mysql_connect("localhost","root","") or die("cant connect to server.");
mysql_select_db("databaseimage") or die("cant connect to database");
echo "name:";
echo $name = $_FILES['myfile']['name'];
echo "type ";
echo $type = $_FILES['myfile']['type'];
echo "<BR>";echo "Size: ";
echo $size = $_FILES['myfile']['size'];
echo "temp: ";
echo $temp = $_FILES['myfile']['tmp_name'];
echo "error code: ";
echo $error = $_FILES['myfile']['error'];
echo "file contents: ";
echo $file_contents = addslashes(file_get_contents($_FILES['myfile']['tmp_name']));
echo "<BR>";
if (!$insert = mysql_query("INSERT INTO table1 VALUES ('','$name','$file_contents')"))
echo "problem uploading file";
else {$last_id = mysql_insert_id();
echo "Image uploaded.";
echo "<BR>";
echo "<img src=get.php?id=$last_id>";
}
答案 0 :(得分:0)
将您的php文件保存为img.php
,并且get.php
和get.php
代码类似,
if(isset($_REQUEST['id'])){
mysql_connect("localhost","root","") or die("cant connect to server.");
mysql_select_db("databaseimage") or die("cant connect to database");
$sql_result = mysql_query("SELECT name FROM table1 WHERE id= $_REQUEST['id']");
$row = mysql_fetch_row($sql_result);
echo $row[0];
}