gpt4 book ai didi

php - 图片上传错误

转载 作者:行者123 更新时间:2023-11-30 23:33:12 24 4
gpt4 key购买 nike

我想通过php上传图片到mysql数据库。我以前用它没有任何问题,但现在我不能。这是我的代码::

图片.php

 <form action='image2.php' method='POST' entype='multipart/form-data'>
<b> Code :: </b> <input type='text' name='randomValue'> <br />
<b> Upload your image :: </b> <input type='file' name='image'> <br />
<input type='submit' name='submitX' value='Complete Registration'>
</form>

image2.php

 if(  isset($_POST['submitX'] ) )   {
include('DB.php');

$test = trim( addslashes( $_POST['randomValue'] ) );

$image = addslashes( file_get_contents( $_FILES['image']['tmp_name'] ) );
$size = getimagesize( $_FILES['image']['tmp_name'] );

if( $size > 0 ) {
mysql_query(" INSERT INTO test VALUES ('' , '$test', '$image') ") or die(mysql_error());
}

}

?>

错误是::

 Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in  E:\xampp\htdocs\MyWork\test\image2.php on line 8

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in E:\xampp\htdocs\MyWork\test\image2.php on line 9

最佳答案

表单上没有名称为 img_name 的元素,请在表单中将其更改为 image_name

  <b> Upload your image :: </b> <input type='file' name='image_name'> <br />

$_POST['image'] 在从帖子获取数据的代码中。

   $test = trim( addslashes( $_POST['img_name'] ) );

应该是

   $test = trim( addslashes( $_POST['name'] ) );

关于php - 图片上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9543764/

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