<p>J&aelig;ja, n&uacute; er b&uacute;i&eth; a&eth; kenna f&oacute;lki a&eth; b&uacute;a
til fr&eacute;tta kerfi og gestab&oacute;k og svaka f&iacute;ner&iacute;. &THORN;a&eth;
v&aelig;ri ekki verra ef &thorn;a&eth; v&aelig;ri h&aelig;gt a&eth; uploada
myndum me&eth; &thorn;essu &ouml;llu saman, er &thorn;a&eth;?
&Eacute;g var einmitt a&eth; vesenast &iacute; morgun vi&eth; a&eth; gera function
sem uploadar myndum. &Eacute;g &aacute;kva&eth; a&eth; reyna a&eth; bjarga kannski
nokkrum fr&aacute; &thorn;v&iacute; a&eth; ey&eth;a t&iacute;ma &iacute; &thorn;essa
vitleysu &thorn;annig &eacute;g &aacute;kva&eth; bara a&eth; p&oacute;sta &thorn;essu
vel commentu&eth;u h&eacute;rna &aacute; huga. Vonandi hj&aacute;lpar &thorn;etta
einhverjum, og muni&eth;i a&eth; l&iacute;klegasta &aacute;st&aelig;&eth;an
fyrir a&eth; &thorn;etta virki ekki er a&eth; &thorn;a&eth; s&eacute;u ekki
skrifr&eacute;ttindi &aacute; m&ouml;ppunni sem &thorn;i&eth; eru&eth; a&eth;
reyna a&eth; uploada &iacute;.</p>
<p>1. upload.php - skr&aacute;in me&eth; forminu.</p>
<p>&lt;?
if(!isset($userfile))
{
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&nbsp;&nbsp;&lt;html&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Senda skr&aacute; &aacute; server&lt;/title&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form enctype=&quot;multipart/form-data&quot; action=&quot;&lt;? echo $PHP_SELF; ?&gt;&quot; method=&quot;post&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1000000000&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Skr&aacute;: &lt;input name=&quot;userfile&quot; type=&quot;file&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;Senda&quot; /&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;
&nbsp;&nbsp;&lt;/html&gt;
&lt;?
}
else
{
&nbsp;&nbsp;include(&quot;funcupload.php&quot;);

&nbsp;&nbsp;$maxHeight = &quot;300&quot;; //Hva&eth; m&aacute; myndin vera h&aacute;?
&nbsp;&nbsp;$maxWidth = &quot;300&quot;; //Hva&eth; m&aacute; myndin vera brei&eth;?
&nbsp;&nbsp;$picName = &quot;nws&quot;; //Hva&eth; &aacute; myndin a&eth; heita, &eacute;g p&uacute;sla &thorn;v&iacute; saman &uacute;r hvar &eacute;g nota &thorn;etta og svo Idi&eth; sem er &iacute; grunninum :)
&nbsp;&nbsp;$picID = &quot;69&quot;; //H&eacute;r &aelig;tti &iacute; rauninni a&eth; vera einhver breyta, t.d Idi&eth; sem er veri&eth; a&eth; setja &iacute; grunnin.
&nbsp;&nbsp;//Userfile er tmp sta&eth;setningin &aacute; myndinni og userfile_type er hva&eth;a tegund af skr&aacute; &thorn;etta er.
&nbsp;&nbsp;$success = picUpload($userfile, $maxHeight, $maxWidth, $picName, $picID, $userfile_type);</p>
<p>&nbsp;&nbsp;//Ef &thorn;etta er array, &thorn;&aacute; er villa :)
&nbsp;&nbsp;if (is_array($success))
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;foreach($success as $key =&gt; $value)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $value.&quot;&lt;br&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
}</p>
<p>&nbsp;</p>
<p>2. funcupload.php - functioni&eth; sj&aacute;lft sem uploadar myndinni.</p>
<p>&lt;?</p>
<p>function picUpload($userfile, $maxHeight, $maxWidth, $picName, $picID, $picType)
{
&nbsp;&nbsp;//Skilar sl&oacute;&eth;inni a&eth; r&oacute;tarm&ouml;ppunni, t.d /home/notendanafn/www/
&nbsp;&nbsp;global $DOCUMENT_ROOT;</p>
<p> &nbsp;&nbsp;//Athugar hvort einhverju hefur veri&eth; uploada&eth;. Ef ekki,
&thorn;&aacute; h&aelig;ttir h&uacute;n.
&nbsp;&nbsp;if ($userfile == &quot;none&quot;)
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;}
&nbsp;&nbsp;else
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;//GetImageSize skilar arrayi me&eth; h&aelig;&eth; og breidd myndarinnar. Td. er $size[3] = &quot;width=(breidd myndarinnar) height=(h&aelig;&eth; myndarinnar)&quot; &thorn;etta er gott &thorn;egar ma&eth;ur er a&eth; s&aelig;kja
&nbsp;&nbsp;&nbsp;&nbsp;myndheiti &uacute;r gagnagrunni.
&nbsp;&nbsp;&nbsp;&nbsp;$size = GetImageSize (&quot;$userfile&quot;);</p>
<p> &nbsp;&nbsp;&nbsp;&nbsp;//Ef myndin er og h&aacute; e&eth;a brei&eth; skilar h&uacute;n villu.
&nbsp;&nbsp;&nbsp;&nbsp;if(($size[0] &gt; $maxWidth) || ($size[1] &gt; $maxHeight))
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error[] = &quot;Myndin m&aacute; ekki vera st&aelig;rri en &quot;.$maxWidth.&quot;x&quot;.$maxHeight.&quot;. (H&uacute;n er &quot;.$size[0].&quot;x&quot;.$size[1].&quot;)&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $error;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Finnur hva&eth;a ending &aacute; a&eth; vera &aacute; skjalinu, h&aelig;gt a&eth; b&aelig;tia vi&eth; og breyta ef ma&eth;ur vill a&eth;rar endingar.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch($picType)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;image/x-png&quot;:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type = &quot;.png&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;image/gif&quot;:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type = &quot;.gif&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &quot;image/pjpeg&quot;:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$type = &quot;.jpg&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Ef endingin er ekki skilgreind er skr&aacute;in ekki leyfileg og forriti&eth; h&aelig;ttir a&eth; keyra.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset($type))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$error[] = &quot;Ekki leyfileg tegund af skr&aacute;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $error;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Ef h&uacute;n kemst hinga&eth; er allt &iacute; lagi og myndin &aelig;tti a&eth; fara &aacute; sinn sta&eth; :)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Muna a&eth; breyta foldernum til &thorn;ess a&eth; uploada myndinni &iacute;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(exec(&quot;cp $userfile $DOCUMENT_ROOT/folerinn til uploada myndinni &iacute;/$picName$picID$type&quot;))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
}</p>
<p>******************************************************************************************</p>
<p>Ef ykkur dettur &iacute; hug einhver lei&eth; til &thorn;ess a&eth; betrum
b&aelig;ta &thorn;etta, e&eth;a rekist &aacute; einhverjar villur, endilega
l&aacute;ti&eth; mig vita :)</p
*————————-*