【发布时间】:2014-05-13 10:46:21
【问题描述】:
我在表单中有这个 html
<input name="image" type="file" />
这是在php中
$actorsex = mysqli_real_escape_string($connect, $_POST['ActorSex']);
$actoraccent = mysqli_real_escape_string($connect, $_POST['ActorAccent']);
$language = mysqli_real_escape_string($connect, $_POST['Language']);
$logo = addslashes(file_get_contents($connect, $_FILES['image']['tmp_name']));
$aftereffects = mysqli_real_escape_string($connect, $_POST['AfterEffects']);
$sql="INSERT INTO orders (name, email, website, phone, companyname, productservice, voiceover, videowritten, targetcustomer, productsolve, featurebenefit, briefoutline, productbenefit, videoideas, calltoaction, actorsex, actoraccent, language, logo, aftereffects)
VALUES ('$name', '$email', '$website', '$phone', '$companyname', '$productservice', '$voiceover', '$videowritten', '$targetcustomer', '$productsolve', '$featurebenefit', '$briefoutline', '$productbenefit', '$videoideas', '$calltoaction', '$actorsex', '$actoraccent', '$language', '$logo', '$aftereffects')";
还有更明显的,但我不想淹没屏幕。图像数据没有传递到数据库,是的,徽标列是一个 mediumblob(我知道这不是黄金方式,而是我需要为这个项目完成的方式)。
提前致谢!
【问题讨论】:
-
哦,我应该补充一点,表单中的所有其他内容都可以正常工作并通过。
-
enctype="multipart/form-data"是您表单的一部分并使用 POST 作为方法吗?如果不是,请添加它。 -
不客气,然后使用
var_dump($_FILES);看看是否有任何结果。很难说,因为我们需要查看更多代码才能确定。检查您的所有变量是否已检出并将错误报告添加到文件顶部error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);如果您还没有这样做。 -
为什么要这样做? 100 次中有 99 次,当经验不足的开发人员想要将文件作为 blob 添加到数据库时,这是错误的设计决策。确实很少有人可能想要这样做(比如您需要对 blob 数据进行二进制搜索)。通常,指向服务器上文件位置的 URL 或链接最适合存储在数据库中。
-
这是我返回的错误报告:array(1) { ["image"]=> array(5) { ["name"]=> string(19) "g2aheaderbanner.png " ["type"]=> string(9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpn2SNIJ" ["error"]=> int(0) ["size"] => int(21089) } } 警告:file_get_contents() 期望参数 1 为字符串,对象在 /hermes/bosweb26b/b2309/ipg.ursiteup/actvidsale/purchase-handler.php 中的第 29 行 1 记录添加第 29 行是带有 $logo 变量的行。