Q695 Posted April 24, 2013 Share Posted April 24, 2013 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? Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/ Share on other sites More sharing options...
requinix Posted April 24, 2013 Share Posted April 24, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426398 Share on other sites More sharing options...
Q695 Posted April 24, 2013 Author Share Posted April 24, 2013 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++; }} Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426410 Share on other sites More sharing options...
requinix Posted April 24, 2013 Share Posted April 24, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426424 Share on other sites More sharing options...
Q695 Posted April 24, 2013 Author Share Posted April 24, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426429 Share on other sites More sharing options...
Q695 Posted April 24, 2013 Author Share Posted April 24, 2013 Also if you comment the getimagesize pram it will upload the file, but not get the image size. Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426433 Share on other sites More sharing options...
requinix Posted April 24, 2013 Share Posted April 24, 2013 Where's the third print_r() coming from? It's the second time it dumps out $_FILES but you only do it once in that code. Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426438 Share on other sites More sharing options...
Q695 Posted April 24, 2013 Author Share Posted April 24, 2013 Oh, it was clearing the submitted data after it was accessed once Link to comment https://forums.phpfreaks.com/topic/277263-functiongetimagesize-failed-to-open-stream-error/#findComment-1426445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.