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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:18:19+00:00 2026-06-16T14:18:19+00:00

I have a php script I’m using to convert an uploaded image into half

  • 0

I have a php script I’m using to convert an uploaded image into half it’s quality so I can save server space, but it isn’t working I’m new to PHP so hopefully someone can help me where I am going wrong.

if(isset($_FILES['t1']['name'])){
    $file = rand(0, 10000000).$_FILES['t1']['name'];
    if (move_uploaded_file($_FILES['t1']['tmp_name'], $file)) {
        if($fp = fopen($file,"rb", 0))
        {
           $picture = fread($fp,filesize($file));
           fclose($fp);
           $img = imagecreatefrompng($file);
           imagepng($img, $file, 6); //6 quality setting
           imagedestroy($img);
           $tag1 = '<img src="'.$file.'" alt="" class="default" />';
//unlink($file);
echo "<script>$(document).ready(function() {var write = $('.item:nth-child(1)').html();localStorage.item1Pantry = write;});</script>";      
        }
    }


}
  • 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-16T14:18:21+00:00Added an answer on June 16, 2026 at 2:18 pm

    PNG is lossless compression. When you set “quality” to 6, you are really just using a mediocre compression method, likely taking up more space. Use 9 for the highest compression (at the expense of slightly more CPU usage, which is hardly noticeable unless you’re doing batch processing).

    You might also look into Yahoo!’s image compression, for more lossless optimizations.

    Also, you really shouldn’t be allowing users to specify file names, even in part. You wouldn’t be too pleased if someone uploaded remote_control_script.php. Never trust what users upload.

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

Sidebar

Related Questions

I have PHP page where users can upload photos (using Ajax & PHP script).
I have PHP page where users can upload photos (using Ajax & PHP script).
I have a PHP script that can encode a PNG image to a Base64
I have PHP script that fetches information from a backend server and saves into
I have php script that creates a temporary watermark image for users that are
I have a PHP script running on my LAMP server that requires certain files
I have a php script that inserts data from an Android app into a
I have a PHP script that creates an entry into a mysql database. The
I am using PHP and Mysql I have PHP script in which I rollback
I have a php script which can take some GET params. I would like

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.