Jump to content

[function.getimagesize]: failed to open stream error


Go to solution Solved by requinix,

Recommended Posts

The server I'm using is WAMP, and it does upload the image every time without error, but I'm recieving this error:

Warning: getimagesize(C:\wamp\tmp\php11AC.tmp) [function.getimagesize]: failed to open stream: No such file or directory in C:\........................... on line 15

 

the code is as follows

$name = $_FILES['creature_image']['name'];
$temp = $_FILES['creature_image']['tmp_name'];
$type = $_FILES['creature_image']['type'];
$size = $_FILES['creature_image']['size'];
print_r($_FILES);

$img_size = getimagesize( $temp ); //size of uploaded image
echo "<br>";
print_r($img_size);
$width=		$img_size[0];
$height=		$img_size[1];


the print_r dumps are:

Array ( [creature_image] => Array ( [name] => hare-rabbit-notes-and-que-006[1].jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\phpF25E.tmp [error] => 0 => 35343 ) )
Array ( [0] => 460 [1] => 276 [2] => 2 [3] => width="460" height="276" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
Array ( [creature_image] => Array ( [name] => hare-rabbit-notes-and-que-006[1].jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\phpF25E.tmp [error] => 0 => 35343 ) )

 

Why am I getting the error when data is there?

The first print_r() is happening twice. There's some code you haven't shown us. A loop, perhaps?

 

[edit] Cut to the chase. Did you move_uploaded_file()? That moves the file. It's not there anymore.

Edited by requinix

Before that I have developer implementation comments.

 

The repeat is for verification that data is still there after the first print_r.

 

That's how $_file is handled by print_r.

 

That did remove the error, but I need it to upload images.

 

Here is the code:

while ($m <= 100) {

//random charicter generator
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < 64; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
$path_rand = $randomString;
//echo $path_rand;


$sql_img_test= "SELECT * FROM $table_name WHERE $var_check='$path_rand' limit 1";
$result_img = mysql_query($sql_img_test, $con) or die ("can not generate result " . mysql_error());
$row_img = mysql_fetch_assoc($result_img); 
if (!$row_img){
$m=101;
} else {
$m++;
}}

Then I'll go with the reply I was going to make before I saw the repeated print_r():

 

There's no way you're getting that error and the code is working. If that error occurs then getimagesize() will completely fail. There's something else going on.

Fine don't believe that it works, and run it yourself:

<?php
//$path folder of location being uploaded to on recieving page
//$path full path of image
//$table_name name of table being checked
//$var_check name of variable in table
//$path_rand image path in directory

// loads image variables
$name = $_FILES['creature_image']['name'];
$temp = $_FILES['creature_image']['tmp_name'];
$type = $_FILES['creature_image']['type'];
$size = $_FILES['creature_image']['size'];
print_r($_FILES);

$img_size = getimagesize( $temp ); //size of uploaded image
echo "<br>";
print_r($img_size);
$width=		$img_size[0];
$height=		$img_size[1];

//echo "$width X $height <br>";

//requirements
$maxwidth = 1280;
$maxheight = 1280;
$allowed = array('image/jpeg' , 'image/png' , 'image/gif');



if (in_array($type, $allowed)){
$m=0;
while ($m <= 100) {

//random charicter generator
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < 64; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
$path_rand = $randomString;
//echo $path_rand;


$sql_img_test= "SELECT * FROM $table_name WHERE $var_check='$path_rand' limit 1";
$result_img = mysql_query($sql_img_test, $con) or die ("can not generate result " . mysql_error());
$row_img = mysql_fetch_assoc($result_img); 
if (!$row_img){
$m=101;
} else {
$m++;
}}

//image load path
$path= "$path" . $path_rand . '.jpg';
echo "<br> $path";

// uploading file, and create database entry
move_uploaded_file($temp, $path); //places image in file location
} else {
echo "type not an image.";
}

?>

Now you should see that it creates the error while working properly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.