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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:22:29+00:00 2026-06-02T10:22:29+00:00

Whit the follow code: $file = fopen(‘php://input’, ‘r’); $temp = tmpfile(); $imageSize = stream_copy_to_stream($file,

  • 0

Whit the follow code:

$file = fopen('php://input', 'r');
$temp = tmpfile();
$imageSize = stream_copy_to_stream($file, $temp);
$imageDimensions = getimagesize($file); // Error here
$imageInfos = pathinfo($_GET['selected-image']);

I get this error
getimagesize() expects parameter 1 to be string, resource given

Because $file is a resource of fopen. How I can have a resource and a string if I can’t read php://input twice?


UPDATE

I have tried this:

$file = fopen('php://input', 'r');
$tempName = tempnam(sys_get_temp_dir(), '.upload');
$imageSize = fwrite(fopen($tempName, 'w+'), stream_get_contents($file));
$imageDimensions = getimagesize($tempName);
$imageInfos = pathinfo($_GET['selected-image']);

// Unlinks and other stuffs

The error:

Notice: getimagesize() [function.getimagesize]: Read error! in 

Thanks!

  • 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-02T10:22:30+00:00Added an answer on June 2, 2026 at 10:22 am

    Because getimagesize() only accepts string filenames, not resources, you will need to use tempnam() to create a temporary file with a name that you can pass to getimagesize().

    $file = fopen('php://input', 'r');
    $tempName = tempnam('/var/tmp', 'img_');
    $temp = fopen($tempName, 'w');
    $imageSize = stream_copy_to_stream($file, $temp);
    fclose($temp);
    $imageDimensions = getimagesize($tempName);
    

    This assumes that the user running PHP has write and read permissions to the directory /var/tmp, but if it doesn’t you can change to a directory that the user does have r/w permissions to.

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

Sidebar

Related Questions

I'm literally going crazy whit these six rows of code. NB: nome and prezzo
How can I add parameters to URL whit PHP. In javascript I use something
I'm low level as3 programmer and I need help whit this code: I have
I'm trying to control my code flow whit the Node.JS module called asyncblock, it
Recently,I want to lean the linux OS,but whit the awful source code I feel
Me back again whit a PHP mySQLi pagination problem... When I rune the script
I've got a UILabel whit a bunch of text but the text is stopping
i need to replace the content of one div whit the content of another.
im starting whit Nhibernate and have managed to get a few examples working, but
I have a problem whit binding in wpf i have a textbox where 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.