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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:16:00+00:00 2026-05-29T10:16:00+00:00

Ok so the problem seems to be in the function not creating the image,

  • 0

Ok so the problem seems to be in the function not creating the image, or in the script it self which does not pass the image to the function

Here is the upload script (note: this is injected into AJAX)

    $path = "cache/";

    $valid_formats = array("jpg", "png", "gif", "jpeg");
    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
        {
        $name = $_FILES['photoimg']['name'];
        $size = $_FILES['photoimg']['size'];

        if(strlen($name))
                {
                ist($txt, $ext) = explode(".", $name);
                if(in_array($ext,$valid_formats))
                {
                if($size<(2024*2024))
                    {
                    $new_file = "header.".$ext;
                    $tmp = $_FILES['photoimg']['tmp_name'];
                    if(move_uploaded_file($tmp, $path.$new_file))
                    {

            echo "<img src='cache/".$new_file."?".time()."'  class='preview'>";

               createHeader($new_file);                                 
                    }

                    else
                    echo "failed";
                    }

                    else
                    echo "Image file size max 1 MB";                    
                    }
                    else
                echo "Invalid file format..";   
                }

            else
                echo "Please select image..!";

            exit;
        }

now here is the function

function createHeader($new_file) {

$path = "uploads/";
$image = "cache/";
$width = 800;

    if(preg_match('/[.](jpg)|(jpeg)$/', $new_file)) {  

        $im = imagecreatefromjpeg($image . $new_file); 

    } else if (preg_match('/[.](gif)$/', $new_file)) {  

        $im = imagecreatefromgif($image . $new_file);   
        imagecolortransparent($im, black);      

    } else if (preg_match('/[.](png)$/', $new_file)) {  

        $im = imagecreatefrompng($image . $new_file);   
    }  

    imagealphablending($im, false);
    imagesavealpha($im, true);  

    $ox = imagesx($im);  
    $oy = imagesy($im);  

    $nx = $width;  
    $ny = floor($oy * ($width / $ox) ); 

    imagecopyresampled($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);      
    imagealphablending($im, true);  
    if(!file_exists($path)) {  
      if(!mkdir($path)) {  
           die("There was a problem. Please try again!");  
      }  
       }  

    imagejpeg($nm, $path . $new_file, 100);

    imagedestroy($im);
    imagedestroy($nm);

}

In logic what the code must do is if a user using my cms is loged-in he or she can change the header on the page by clicking an icon which will make a jQuery call to edit.php passing needed query string. From there own user can upload a new image which will be renamed header.jpg and over-write the original image

The header.jpg has to be uploaded into uploads/ directory and a copy of original image cache/ should be unlinked ones the function can create a copy and put it into uploads/ directory.

What is happening is that the first script is uploading the file and is putting it into cache/ directory but the function does not seem to work and does nothing for uploads/ directory.

Any idea what I may be doing wrong or not doing that is causing this annoying problem?

  • 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-05-29T10:16:01+00:00Added an answer on May 29, 2026 at 10:16 am

    $path = “cache/”;

    $valid_formats = array("jpg", "png", "gif", "jpeg");
    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
        {
        $name = $_FILES['photoimg']['name'];
        $size = $_FILES['photoimg']['size'];
    
        if(strlen($name))
                {
                list($txt, $ext) = explode(".", $name);
                if(in_array($ext,$valid_formats))
                {
                if($size<(2024*2024))
                    {
                    $new_file = "header.".$ext;
                    $tmp = $_FILES['photoimg']['tmp_name'];
                    if(move_uploaded_file($tmp, $path.$new_file))
                    {
    
               // This needs to happen before the echo of the image tag
               createHeader($new_file);                                 
    
            echo "<img src='cache/".$new_file."?".time()."'  class='preview'>";
                    }
    
                    else
                    echo "failed";
                    }
    
                    else
                    echo "Image file size max 1 MB";                    
                    }
                    else
                echo "Invalid file format..";   
                }
    
            else
                echo "Please select image..!";
    
            exit;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So there seems to be this problem with GNU Make's $(wildcard) function keeping a
The problem seems very strange. I have a AJAX helper function within a same
My problem seems to be quite simple, but it's not working the intuitive way.
My problem seems to be this: heap data allocated by one thread (that later
Today I stumbled about a Problem which seems to be a bug in the
This seems to be a common problem but I cannot find a solution. I
I have a problem creating a for-loop using Javascript. It seems everyting is fine
I am creating an AJAX PHP upload script, but I am having troubles. After
Ive had a problem that I cant fix while creating an image carousel in
I have such problem: I'm creating a container and it's content at runtime. Here's

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.