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 8680151
In Process

The Archive Base Latest Questions

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

<?php require_once (‘../index.php’); if ($_FILES[file][error] > 0) { echo Error: . $_FILES[file][error] . <br/>;

  • 0
<?php
require_once ('../index.php'); 
if ($_FILES["file"]["error"] > 0)
{
    echo "Error: " . $_FILES["file"]["error"] . "<br/>";
}
else
{   
}
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000) && in_array($extension, $allowedExts))
{
    if ($_FILES["file"]["error"] > 0)
    {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br/>";
    }
    else
    {
        if (file_exists("../uploadedImages/" . $_FILES["file"]["name"]))
        {
            echo $_FILES["file"]["name"] . " already exists. ";
        }
        else
        {
            move_uploaded_file($_FILES["file"]["tmp_name"],
            "../uploadedImages/" . $_FILES["file"]["name"]);
            echo "Du har laddat upp en bild.";
        }
    }
}
else
{
    echo "Invalid file";
}

I wanna be able to resize my image, when i upload my image.
The code that I have now Im uploading a image to my uploadedImages folder, and I want to resize my images to small thumbs.

  • 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-12T21:10:24+00:00Added an answer on June 12, 2026 at 9:10 pm

    This script resize an Image into two 60px and 25px. Take a look at $newwidth you have to modify size values.

    <?php 
    
     define ("MAX_SIZE","400");
    
     $errors=0;
    
     if($_SERVER["REQUEST_METHOD"] == "POST")
     {
            $image =$_FILES["file"]["name"];
     $uploadedfile = $_FILES['file']['tmp_name'];
    
      if ($image) 
      {
      $filename = stripslashes($_FILES['file']['name']);
            $extension = getExtension($filename);
      $extension = strtolower($extension);
     if (($extension != "jpg") && ($extension != "jpeg") 
    && ($extension != "png") && ($extension != "gif")) 
      {
    echo ' Unknown Image extension ';
    $errors=1;
      }
     else
    {
       $size=filesize($_FILES['file']['tmp_name']);
    
    if ($size > MAX_SIZE*1024)
    {
     echo "You have exceeded the size limit";
     $errors=1;
    }
    
    if($extension=="jpg" || $extension=="jpeg" )
    {
    $uploadedfile = $_FILES['file']['tmp_name'];
    $src = imagecreatefromjpeg($uploadedfile);
    }
    else if($extension=="png")
    {
    $uploadedfile = $_FILES['file']['tmp_name'];
    $src = imagecreatefrompng($uploadedfile);
    }
    else 
    {
    $src = imagecreatefromgif($uploadedfile);
    }
    
    list($width,$height)=getimagesize($uploadedfile);
    
    $newwidth=60;
    $newheight=($height/$width)*$newwidth;
    $tmp=imagecreatetruecolor($newwidth,$newheight);
    
    $newwidth1=25;
    $newheight1=($height/$width)*$newwidth1;
    $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
    
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
     $width,$height);
    
    imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1, 
    $width,$height);
    
    $filename = "images/". $_FILES['file']['name'];
    $filename1 = "images/small". $_FILES['file']['name'];
    
    imagejpeg($tmp,$filename,100);
    imagejpeg($tmp1,$filename1,100);
    
    imagedestroy($src);
    imagedestroy($tmp);
    imagedestroy($tmp1);
    }
    }
    }
    //If no errors registred, print the success message
    
     if(isset($_POST['Submit']) && !$errors) 
     {
       // mysql_query("update SQL statement ");
      echo "Image Uploaded Successfully!";
    
     }
     ?>
    

    Finds file extensions.

    function getExtension($str) {
    
             $i = strrpos($str,".");
             if (!$i) { return ""; } 
             $l = strlen($str) - $i;
             $ext = substr($str,$i+1,$l);
             return $ext;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML form POSTing to the following index.php: <?php require_once(/home/full/path/to/included/file.php); ?> And
I have an index.php file that has 3 includes <?php require_once('mod.php'); $mod = new
I have a file index.php in root directory: <?php require_once ./include/common.php; ?> and file
My PHP script is as follows: <?php require_once('connectvars.php'); $file = $_FILES['image']['name']; $target = GW_UPLOADPATH
index.php <?php require_once('fr.php'); header('Location:'.abspath().directory()); ?> fr.php <?php require_once('functions.php'); ?> functions.php function abspath() { return
index.php: <form action=update_db.php method=post> <?php require_once 'modules/' . $currentModule . '.php'; ?> </form> modules/
My first class: <?php require_once( 'error/DisconnectedHandler.php' ); require_once( 'error/NoSuchRequestHandler.php' ); class NetworkManager { public
I have following setup. index.php require_once common.php; ... common.php ... $obj = new MyClass;
I have 2 very simple scripts: <?php require_once 'facebook.php'; $facebook = new Facebook(array( 'appId'
If I try to open this simple file in my Browser: <?php require_once 'classes/settings.php';

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.