2

私の質問はこれに似ていますが、最後のビットで立ち往生しています!

$maxwidth次のコードは、HTML フォームから送信されたファイルを取得し、そのサイズを 2 つの事前定義された値とに対してチェックします$maxheight。幅が広すぎる場合は、画像のサイズが変更されます。

次に行うことは、新しくサイズ変更された画像を元の変数に再割り当てして$tmpName、スクリプトの残りの部分で処理できるようにすることだけです。

次のコードは、これらのエラーを返します。

Warning: fopen() expects parameter 1 to be string, resource given in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 43

Warning: filesize() [function.filesize]: stat failed for Resource id #4 in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 44

Warning: fread(): supplied argument is not a valid stream resource in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 44

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 46

私はそれを手に入れるのにかなり近づいていると思いますが、誰か助けてもらえますか?ありがとう。

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];  

            list($width,$height)=getimagesize($tmpName);

            if ($width>$height && $width>$maxwidth) {
                $newheight=($height/$width)*$maxwidth;
                $newwidth=$maxwidth;
                $imageResized = imagecreatetruecolor($newwidth, $newheight);
                $imageTmp     = imagecreatefromjpeg ($tmpName);
                imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                $tmpName=$imageResized;

                // My problem lies somewhere here ^^^^
            }

      // Read the file 
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);


      // Create the query and insert
      // into our database.
      $query = "INSERT INTO tblPrints ";
      $query .= "(title,full_image) VALUES ('IMG-TEST','$data')";
      $results = mysql_query($query, $link);

      // Print results
      print "Thank you, your file has been uploaded.";

}
else {
   print "No image selected/uploaded";
}
4

1 に答える 1

0

6 行目から 17 行目は、ファイル名を画像データ自体に置き換えます。これが、の意味です。

Warning: fopen() expects parameter 1 to be string, resource given

したがって、次の行では、

  // Read the file 
  $fp      = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);

ファイルを読む必要はありません。条件付きプロセスが実行された場合は、必要なのは

$data = $tmpname // sounds strange, remember: $tmpname is not the name any more
于 2013-05-15T15:42:02.173 に答える