{"id":89,"date":"2008-02-29T14:28:46","date_gmt":"2008-02-29T12:28:46","guid":{"rendered":"http:\/\/www.hermione.de\/blog\/?p=89"},"modified":"2008-03-03T16:48:04","modified_gmt":"2008-03-03T14:48:04","slug":"bild-hochladen-und-verkleinern-php","status":"publish","type":"post","link":"http:\/\/blog.hermione.de\/?p=89","title":{"rendered":"Bild hochladen und mit gd lib verkleinern [php]"},"content":{"rendered":"<h4>File upload im HTML Formular<\/h4>\n<p><em>&lt;form action=&#8220;upload.php&#8220; method=&#8220;POST&#8220; enctype=&#8220;multipart\/form-data&#8220;&gt;<br \/>\n&lt;input type=&#8220;text&#8220; name=&#8220;img&#8220; value=&#8220;&#8220; size=&#8220;50&#8243; maxlength=&#8220;256&#8243;&gt;<br \/>\n&lt;input name=&#8220;upfile&#8220; type=&#8220;file&#8220; size=&#8220;50&#8243; maxlength=&#8220;1000000&#8243; accept=&#8220;img\/*&#8220;&gt;<br \/>\n&lt;input type=&#8220;submit&#8220; value=&#8220;submit&#8220;&gt;<br \/>\n&lt;\/form&gt;<\/em><\/p>\n<h4>Bild verkleinert speichern mit gd lib<\/h4>\n<p><!--more--><\/p>\n<table class=\"rosa\">\n<tr>\n<td>\n<pre><code>if (array_key_exists(\"upfile\",$_FILES)) {\r\n\r\n         <strong># upload nur wenn file nicht zu gross ist<\/strong>\r\n         if($_FILES[\"upfile\"][\"size\"] &lt; = $max_size) {\r\n\r\n            <strong># upload nur wenn mime-type image\/*<\/strong>\r\n            if (preg_match(\"\/image\/(.*)$\/\", $_FILES[\"upfile\"][\"type\"],$mm)) {\r\n\r\n               <strong># upload file wird unter $tmpdir.$filename abgespeichert<\/strong>\r\n               \/\/copy($_FILES[\"upfile\"][\"tmp_name\"], $tmpdir . $filename);\r\n               if (move_uploaded_file($_FILES['upfile']['tmp_name'], $tmpdir . $filename)) {\r\n\r\n                 <strong>#image handle fuer gd lib bearbeitung<\/strong>\r\n                  if ($mm[1] == \"jpg\" ) {\r\n                     $oimg = imagecreatefromjpeg($tmpdir.$filename);\r\n                 }\r\n\r\n                 <strong># breite und hoehe des ursprungsbildes<\/strong>\r\n                 $ox = imagesx($oimg);\r\n                 $oy = imagesy($oimg);\r\n\r\n                 <strong># breite und hoehe des neuen bildes<\/strong>\r\n                 $nx = 120;\r\n                 $ny = ($nx\/$ox) * $oy;\r\n\r\n                 <strong># image handle fuer das neue bild<\/strong>\r\n                 $nimg = imagecreatetruecolor($nx, $ny);\r\n\r\n                 <strong># bild verkleinern <\/strong>\r\n                 imagecopyresized($nimg, $oimg, 0, 0, 0, 0, $nx, $ny, $ox, $oy);\r\n\r\n                 <strong># bild speichern und speicherplatzfreigabe<\/strong>\r\n                 imagejpeg($nimg,$imgdir.$filename);\r\n                 imagedestroy($nimg);\r\n                 imagedestroy($oimg);\r\n\r\n                 $_REQUEST[\"img\"] = $imgurl . $filename;\r\n               }\r\n            }\r\n         }\r\n      }\r\n      $rez-&gt;setImg($_REQUEST[\"img\"]);\r\n<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>File upload im HTML Formular &lt;form action=&#8220;upload.php&#8220; method=&#8220;POST&#8220; enctype=&#8220;multipart\/form-data&#8220;&gt; &lt;input type=&#8220;text&#8220; name=&#8220;img&#8220; value=&#8220;&#8220; size=&#8220;50&#8243; maxlength=&#8220;256&#8243;&gt; &lt;input name=&#8220;upfile&#8220; type=&#8220;file&#8220; size=&#8220;50&#8243; maxlength=&#8220;1000000&#8243; accept=&#8220;img\/*&#8220;&gt; &lt;input type=&#8220;submit&#8220; value=&#8220;submit&#8220;&gt; &lt;\/form&gt; Bild verkleinert speichern mit gd lib<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,12],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":0,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}