Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction only works 1 time
    text
    copied!<p>I wrote a script for uploading an image to my server. Users can use it e.g. for uploading their avatars, or their works.</p> <p>This is the function in functions.php</p> <pre><code>function save_image($image, $uploadedfile) { error_reporting(0); $change=""; $abc=""; define ("MAX_SIZE","40000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if ($image) { $filename = stripslashes($image); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") &amp;&amp; ($extension != "jpeg") &amp;&amp; ($extension != "png") &amp;&amp; ($extension != "gif")) { $change='&lt;div class="msgdiv"&gt;Unknown Image extension &lt;/div&gt; '; $errors=1; } else { $size=filesize($uploadedfile); if ($size &gt; MAX_SIZE*1024) { $change='&lt;div class="msgdiv"&gt;You have exceeded the size limit!&lt;/div&gt; '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $uploadedfile; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $uploadedfile; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=$width; $newheight=$height; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $filename = "images/vcard_images/". $image; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } </code></pre> <p>So now I have a form on the page create.php where they can upload 6 of their works. So they select 6 files from their hard drive and then press save. Then I call the function 6 times like this:</p> <pre><code>$work1 = $_FILES["work1"]["name"]; save_image($_FILES["work1"]["name"], $_FILES['work1']['tmp_name']); $work2 = $_FILES["work2"]["name"]; save_image($_FILES["work2"]["name"], $_FILES['work2']['tmp_name']); $work3 = $_FILES["work3"]["name"]; save_image($_FILES["work3"]["name"], $_FILES['work3']['tmp_name']); $work4 = $_FILES["work4"]["name"]; save_image($_FILES["work4"]["name"], $_FILES['work4']['tmp_name']); $work5 = $_FILES["work5"]["name"]; save_image($_FILES["work5"]["name"], $_FILES['work5']['tmp_name']); $work6 = $_FILES["work6"]["name"]; save_image($_FILES["work6"]["name"], $_FILES['work6']['tmp_name']); </code></pre> <p>But the weird part is, if I press SAVE, the page just becomes white. And if I only call the function onces, so only this:</p> <pre><code>$work1 = $_FILES["work1"]["name"]; save_image($_FILES["work1"]["name"], $_FILES['work1']['tmp_name']); </code></pre> <p>It works perfectly fine.. </p> <p>No idea what I'm doing wrong..</p> <p>Kind regards</p> <p>EDIT:</p> <p>Error reporting told me this:</p> <pre><code>Notice: Constant MAX_SIZE already defined in /Applications/XAMPP/xamppfiles/htdocs/vcard2/user/functions.php on line 11 Fatal error: Cannot redeclare getExtension() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/vcard2/user/functions.php:12) in /Applications/XAMPP/xamppfiles/htdocs/vcard2/user/functions.php on line 12 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload