Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:10:26+00:00 2026-06-12T13:10:26+00:00

I wrote a script for uploading an image to my server. Users can use

  • 0

I wrote a script for uploading an image to my server. Users can use it e.g. for uploading their avatars, or their works.

This is the function in functions.php

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") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
        {

            $change='<div class="msgdiv">Unknown Image extension </div> ';
            $errors=1;
        }
        else
        {

 $size=filesize($uploadedfile);


if ($size > MAX_SIZE*1024)
{
    $change='<div class="msgdiv">You have exceeded the size limit!</div> ';
    $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);
}}


}

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:

$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']);

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:

$work1 = $_FILES["work1"]["name"];
save_image($_FILES["work1"]["name"], $_FILES['work1']['tmp_name']);

It works perfectly fine..

No idea what I’m doing wrong..

Kind regards

EDIT:

Error reporting told me this:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:10:28+00:00Added an answer on June 12, 2026 at 1:10 pm

    I would recommend you to have a look at HTML5’s FILE API, which manages multiple files uploading and Drag and Drop system. two recommended scripts if you want to play around:

    http://blueimp.github.com/jQuery-File-Upload/

    and

    https://github.com/weixiyen/jquery-filedrop

    i tried them both and they are nice

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this script to for a contact form on my website, everything works
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
I wrote this script which counts occurrences of particular pattern in a given file.
I have got this JavaScript code for uploading files to my server (named it
I am uploading a file via php move_uploaded_file function and then the file is
I am trying to use JavaScript to upload image to imgur by this example
I want to use Ruby Mechanize to write an auto file uploading script for
Can you tell me what I do wrong. I use PHP. Try to upload
I'm building an image uploading script (for the first time) in Codeigniter and the
I am having trouble with this script. It's an image upload script and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.