{"id":732,"date":"2016-09-06T15:56:50","date_gmt":"2016-09-06T12:56:50","guid":{"rendered":"http:\/\/www.erenali.com\/?p=732"},"modified":"2016-09-06T15:56:50","modified_gmt":"2016-09-06T12:56:50","slug":"yii-form-icinde-dosya-yukleme","status":"publish","type":"post","link":"https:\/\/www.erenali.com\/index.php\/2016\/09\/06\/yii-form-icinde-dosya-yukleme\/","title":{"rendered":"Yii Form i\u00e7inde Dosya Y\u00fckleme"},"content":{"rendered":"<div class=\"38128c0007b0f41e35c6013bb0abf0bf\" data-index=\"1\" style=\"float: left; margin: 10px 10px 10px 0;\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-3908223554810378\"\r\n     data-ad-slot=\"5522206140\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n\n<\/div>\n<p>Form olu\u015ftururken dosya y\u00fcklemek gereken durumlar olu\u015fabilmekte. Bunun i\u00e7in a\u015fa\u011f\u0131daki d\u00fczenlemeleri yaparak istedi\u011fimiz formatta dosyalar\u0131n y\u00fcklenebilmesini sa\u011flayabiliriz.<\/p><div class=\"38128c0007b0f41e35c6013bb0abf0bf\" data-index=\"1\" style=\"float: left; margin: 10px 10px 10px 0;\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-3908223554810378\"\r\n     data-ad-slot=\"5522206140\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n\n<\/div>\n\n<p><strong>view\/ _form<\/strong><\/p>\n<p>widget i\u00e7ine<\/p>\n<blockquote><p><em>&#8216;enableAjaxValidation&#8217;=&gt;false,<\/em><br \/>\n<em>&#8216;htmlOptions&#8217; =&gt; array(<\/em><br \/>\n<em> <span style=\"color: #ff0000;\">&#8216;enctype&#8217; =&gt; &#8216;multipart\/form-data&#8217;,<\/span><\/em><br \/>\n<em> ),<\/em><br \/>\n<em>&#8230;<\/em><\/p>\n<p><em>&lt;div class=&#8221;row&#8221;&gt;<\/em><br \/>\n<em> &lt;?php echo $form-&gt;labelEx($model,&#8217;resimadi&#8217;); ?&gt;<\/em><br \/>\n<em> &lt;?php echo CHtml::activeFileField($model, &#8216;resimadi&#8217;); ?&gt; <\/em><br \/>\n<em> &lt;?php echo $form-&gt;error($model,&#8217;resimadi&#8217;); ?&gt;<\/em><br \/>\n<em> &lt;\/div&gt;<\/em><\/p>\n<p><em>&lt;?php if(!$model-&gt;isNewRecord){ ?&gt;<\/em><br \/>\n<em> &lt;div class=&#8221;row&#8221;&gt;<\/em><br \/>\n<em> &lt;?php echo CHtml::image(Yii::app()-&gt;request-&gt;baseUrl.&#8217;\/duyurular\/&#8217;.$model-&gt;resimadi,&#8221;resimadi&#8221;,array(&#8216;style&#8217;=&gt;&#8217;width:50px;height:50px&#8217;));<\/em><\/p>\n<p><em>\/\/ y\u00fckl\u00fc olan resmi g\u00f6steriyor.<\/em><\/p>\n<p><em>?&gt; <\/em><br \/>\n<em> &lt;\/div&gt;<\/em><br \/>\n<em>&lt;?php } ?&gt;<\/em><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>controller\/create<\/strong><\/p>\n<blockquote><p><em>$model=new Duyurular;<\/em><\/p>\n<p><em>\/\/ Uncomment the following line if AJAX validation is needed<\/em><br \/>\n<em> \/\/ $this-&gt;performAjaxValidation($model);<\/em><\/p>\n<p><em>if(isset($_POST[&#8216;Duyurular&#8217;]))<\/em><br \/>\n<em> {<\/em><br \/>\n<em> $model-&gt;attributes=$_POST[&#8216;Duyurular&#8217;];<\/em><\/p>\n<p><em>$rnd = rand(0,9999);<\/em><br \/>\n<em> $uploadedFile=CUploadedFile::getInstance($model,&#8217;resimadi&#8217;);<\/em><br \/>\n<em> $fileName = &#8220;{$rnd}-{$uploadedFile}&#8221;; \/\/ random number + file name<\/em><br \/>\n<em> $model-&gt;resimadi = $fileName;<\/em><br \/>\n<em> if($model-&gt;save())<\/em><br \/>\n<em> {<\/em><br \/>\n<em> $uploadedFile-&gt;saveAs(Yii::app()-&gt;basePath.&#8217;\/..\/duyurular\/&#8217;.$fileName); \/\/ image will uplode to rootDirectory\/duyurular\/<\/em><br \/>\n<em> $this-&gt;redirect(array(&#8216;view&#8217;,&#8217;id&#8217;=&gt;$model-&gt;id));<\/em><br \/>\n<em> } <\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>$this-&gt;render(&#8216;create&#8217;,array(<\/em><br \/>\n<em> &#8216;model&#8217;=&gt;$model,<\/em><br \/>\n<em> ));<\/em><\/p><\/blockquote>\n<hr \/>\n<p><strong>controller\/update<\/strong><\/p>\n<blockquote><p>\n<em>$model=$this-&gt;loadModel($id);<\/em><\/p>\n<p><em>\/\/ Uncomment the following line if AJAX validation is needed<\/em><br \/>\n<em> \/\/ $this-&gt;performAjaxValidation($model);<\/em><\/p>\n<p><em>if(isset($_POST[&#8216;Duyurular&#8217;]))<\/em><br \/>\n<em> {<\/em><br \/>\n<em> $_POST[&#8216;Duyurular&#8217;][&#8216;resimadi&#8217;] = $model-&gt;resimadi;<\/em><br \/>\n<em> $model-&gt;attributes=$_POST[&#8216;Duyurular&#8217;];<\/em><\/p>\n<p><em>$uploadedFile=CUploadedFile::getInstance($model,&#8217;resimadi&#8217;);<\/em><\/p>\n<p><em>if($model-&gt;save()){<\/em><\/p>\n<p><em>if(!empty($uploadedFile)) \/\/ check if uploaded file is set or not<\/em><br \/>\n<em> {<\/em><br \/>\n<em> $uploadedFile-&gt;saveAs(Yii::app()-&gt;basePath.&#8217;\/..\/duyurular\/&#8217;.$model-&gt;resimadi);<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em>$this-&gt;redirect(array(&#8216;view&#8217;,&#8217;id&#8217;=&gt;$model-&gt;id));<\/em><br \/>\n<em> }<\/em><\/p>\n<p><em> }<\/em><\/p>\n<p><em>$this-&gt;render(&#8216;update&#8217;,array(<\/em><br \/>\n<em> &#8216;model&#8217;=&gt;$model,<\/em><br \/>\n<em> ));<\/em><\/p><\/blockquote>\n<hr \/>\n<p><strong>model\/duyurular<\/strong><\/p>\n<p><strong>rules<\/strong> i\u00e7ine dosya uzant\u0131lar\u0131n\u0131 tan\u0131mlamam\u0131z gerekmekte.<\/p>\n<blockquote><p><em>array(&#8216;resimadi&#8217;, &#8216;file&#8217;,&#8217;types&#8217;=&gt;&#8217;jpg, gif, png&#8217;, &#8216;allowEmpty&#8217;=&gt;true, &#8216;on&#8217;=&gt;&#8217;update&#8217;),\u00a0<\/em><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div class=\"38128c0007b0f41e35c6013bb0abf0bf\" data-index=\"2\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-3908223554810378\"\r\n     data-ad-slot=\"5522206140\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n\n<\/div>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Form olu\u015ftururken dosya y\u00fcklemek gereken durumlar olu\u015fabilmekte. Bunun i\u00e7in a\u015fa\u011f\u0131daki d\u00fczenlemeleri yaparak istedi\u011fimiz formatta dosyalar\u0131n y\u00fcklenebilmesini sa\u011flayabiliriz. view\/ _form widget i\u00e7ine &#8216;enableAjaxValidation&#8217;=&gt;false, &#8216;htmlOptions&#8217; =&gt; array( &#8216;enctype&#8217; =&gt; &#8216;multipart\/form-data&#8217;, ), &#8230; &lt;div class=&#8221;row&#8221;&gt; &lt;?php echo $form-&gt;labelEx($model,&#8217;resimadi&#8217;); ?&gt; &lt;?php echo CHtml::activeFileField($model, &#8216;resimadi&#8217;); ?&gt; &lt;?php echo $form-&gt;error($model,&#8217;resimadi&#8217;); ?&gt; &lt;\/div&gt; &lt;?php if(!$model-&gt;isNewRecord){ ?&gt; &lt;div&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.erenali.com\/index.php\/2016\/09\/06\/yii-form-icinde-dosya-yukleme\/\">Devam\u0131n\u0131 Oku<span class=\"screen-reader-text\">Yii Form i\u00e7inde Dosya Y\u00fckleme<\/span> <i class=\"fas fa-angle-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,6],"tags":[478,491,490,489,488,199,484,479,492,486,487,485,482,483,481,480],"_links":{"self":[{"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/posts\/732"}],"collection":[{"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/comments?post=732"}],"version-history":[{"count":1,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/posts\/732\/revisions"}],"predecessor-version":[{"id":733,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/posts\/732\/revisions\/733"}],"wp:attachment":[{"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/media?parent=732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/categories?post=732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.erenali.com\/index.php\/wp-json\/wp\/v2\/tags?post=732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}