我已经在这上面投入了太多的时间。我是PHP编程的新手,试图掌握基础知识,但昨晚我有点迷失方向,能够让PHP表单上传类似姓名、地址和其他基本数据到我的(MySQL)服务器。
但今天我说让我们进行下一步,也就是将图片上传到服务器。 我在YouTube上看了3个视频,大概重复了100遍的代码并尝试了很多不同的方式。
http://www.youtube.com/watch?v=CxY3FR9doHI
http://www.youtube.com/watch?v=vFZfJZ_WNC4&feature=relmfu
我仍然无法获得它。
简而言之:我有一个连接到服务器的config.php文件,以下是我在上传表单页面上运行的代码:
<html>
<head>
<title>Upload an image</title>
</head>
<body>
<form action="UploadContent.php" method="POST" enctype="multipart/form-data">
File:
<input type="file" name="image"> <input type="submit" value="Upload">
</form>
<?php
// connect to database
include"config.php";
// file properties
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select a profile pic";
else
{
$image = addslashes(file_get_content($_FILES['image']['tmp_name']));
$image_name = addslashes($FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "That isn't a image.";
else
{
$insert = mysql_query("INSERT INTO content VALUES ('','','','','','','','','','$image_name','$image',)");
}
}
?>
</body>
</html>
在插入行中出现所有'', '', '', ''
的原因是因为我将名称放在第10个字段中,图像blob放在第11个字段中,所有前面的都是名字,姓氏和类似于那样的随机信息。我该如何解决这个问题?它返回以下错误:
致命错误:在/home/content/34/9587634/html/WEBPAGE/UploadContent.php的第22行调用未定义的函数file_get_content()
我不知道该怎么办。