1

私はこのフォームを使用しています:

<FORM action="testimage1.php" method="post">
                 <div style="font:bold 10px arial,serif;" >Product Name*</div>
                 <input type="text" name="myuserName" maxlength="50" /><br />
                  <div style="font:bold 10px arial,serif;" >Upload a photo</div>
                 <input name="uploadimage" type="file" /></br>
                 <div style="font:bold 10px arial,serif;">Product Description:</div> <input type="text" name="product" value=""></br>
                 <input id="submit" type="submit" value="submit" /><br />
                 </form>

そしてtest1.phpで

require_once("dbconnect.inc.php");  //for database connection                   
    $db_name="thinstrokes";                                     
     $tbl_name="product";
     $db_selected=mysql_select_db("$db_name")or die("cannot select DB");
    // Connect to server and select databse.
    // username and password sent from form 
    $myusername=$_POST['myusername']; 
    $myproduct=$_POST['product'];
    $filename=$_POST['uploadimage'];

$imgData = file_get_contents($filename);
    $size = getimagesize($filename);
    $sql = "INSERT INTO product
    (productname, image_id , image_type ,image, image_size, image_name,productdesc)
    VALUES
    ('$myusername','11', '{$size['mime']}', '{$imgData}', '{$size[3]}', 
     '{$_FILES['userfile']['name']}','$productdesc')";
    $result=mysql_query($sql) or die("error in uploading/*");

取得エラーは次のとおりです:-

file_get_contents(DSC02945.JPG) [function.file-get-contents]: ストリームを開くことができませんでした: No such file or directory in C:\xampp\htdocs\thinstrokes original site\testimage1.php on line 22

警告: getimagesize(DSC02945.JPG) [function.getimagesize]: ストリームを開くことができませんでした: C:\xampp\htdocs\thinstrokes original site\testimage1.php の 23 行目にそのようなファイルまたはディレクトリはありません

どうすれば修正できますか..???

4

2 に答える 2

3

フォーム宣言に enctype=multipart/form-data が必要です。$_POST 変数の代わりに $_FILES 変数を介してファイルにアクセスします。お気に入り:

<form action="testimage1.php" method="post" enctype="multipart/form-data">
   <input name="uploadimage" type="file" />
</form>

<?php
    $filename = $_FILES['uploadimage']['tmp_name'];   
?>
于 2012-05-31T07:42:09.133 に答える
-1
$imgData = file_get_contents($filename);
$size = getimagesize($filename);
mysql_connect("localhost", "$username", "$password");
mysql_select_db ("$dbname");
$sql = sprintf("INSERT INTO testblob
    (image_type, image, image_size, image_name)
    VALUES
    ('%s', '%s', '%d', '%s')",
    mysql_real_escape_string($size['mime']),
    mysql_real_escape_string($imgData),
    $size[3],
    mysql_real_escape_string($_FILES['userfile']['name'])
    );
mysql_query($sql);
于 2013-06-22T23:38:56.563 に答える