cooldude832 Posted January 8, 2008 Share Posted January 8, 2008 I want to take the raw uploaded files content straight to mysql without having to move it any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/ Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 hi, I think its possible when you upload your file it get saved in temp dir.From $_FILE['tmp_name'] will give you the file hence you can read this file and get the contents from it and use the way you want. regards Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433294 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 I know taht but my stupid host says my temp upload directory is no value in the phpinfo(); Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433296 Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 I know taht but my stupid host says my temp upload directory is no value in the phpinfo(); you mean you cann't upload your files ???? If yes then you must have some dir where your uploaded temp files are been created. I did this print_r($_FILES); $f=file($_FILES['uploadedfile']['tmp_name']); print_r($f); and i am able to see the content of my files. regards Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433298 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 no I can upload fine I just don't want to have to move it from this "temp folder" to another temp folder via copy or move_upload_file and then from that file_get_contents on it then to mysql I get Array ( [image_0] => Array ( [name] => 0.jpg [type] => image/jpeg [tmp_name] => /tmp/phpcAEt9X [error] => 0 => 46013 ) [image_1] => Array ( [name] => 1.jpg [type] => image/jpeg [tmp_name] => /tmp/phpA76po5 [error] => 0 => 83998 ) [image_2] => Array ( [name] => 2.jpg [type] => image/jpeg [tmp_name] => /tmp/phpWXp09f [error] => 0 => 249247 ) [image_3] => Array ( [name] => 3.JPG [type] => image/jpeg [tmp_name] => /tmp/php6Eky5C [error] => 0 => 48347 ) ) on print_r($_FILES); Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433300 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 i think this actually worked file_get_contents($_FILES['image'.$i]['tmp_name']); still have to reproduce the image Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433302 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 this is what I came up with doesn't resize on upload, wondering if I should?? <?php $i = 0; while(!empty($_FILES['image_'.$i])){ $temp = $i+1; if($_FILES['image_'.$i]['error'] == "0"){ if($_FILES['image_'.$i]['size'] < 1200000){ if(in_array($_FILES['image_'.$i]['type'],$image_types)){ $fields_string[] = "Image_".$i; $fields_string[] = "Image_type_".$i; $insert_string[] = "'".mysql_real_escape_string(file_get_contents($_FILES['image_'.$i]['tmp_name']))."'"; $insert_string[] = $_FILES['image_'.$i]['type']; $update_string[] = "Image_".$i." = '".mysql_real_escape_string(file_get_contents($_FILES['image_'.$i]['tmp_name']))."'"; $update_string[] = "Image_type_".$i." = '".$_FILES['image_'.$i]['type']."'"; } else{ $_SESSION['Errors'][] = "The image ".$temp." was not a valid type."; } } else{ $_SESSION['Errors'][] = "The image ".$temp." was too large."; } } else{ if($_FILES['image_'.$i]['error'] != "4"){ $_SESSION['Errors'][] = "There was an error uploading file ".$temp."."; } } $i++; } if(is_array($fields_string)){ $fields_string = ", ".implode(" , ",$fields_string); $insert_string = ", ".implode(" , " ,$insert_string); $update_string = ", ".implode(" , ",$update_string); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433304 Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 hi, i didn't get where you got stucked now?? regards Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433307 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 well I'm trying to resize on upload but the imagecreatefromstring is failing any ideas? the error is Warning: getimagesize(Resource id #7) [function.getimagesize]: failed to open stream: No such file or directory in on line 34 and line 34 is the getimagesize line I don't know why its saying Resource id #7 when I echo it out it looks like binary junk. <?php $im = file_get_contents($_FILES['image_'.$i]['tmp_name'], FILE_BINARY); $im = imagecreatefromstring($im); list($width, $height) = getimagesize($im); $target = 150; if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } $width1 = round($width * $percentage); $height1 = round($height * $percentage); if($_FILES['image_'.$i]['type'] == "image/jpg" || $_FILES['image_'.$i]['type'] == "image/pjpg"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height) or die("error copyresize"); $imgdata = imagejpeg($thumb); } elseif($_FILES['image_'.$i]['type'] == "image/gif" || $_FILES['image_'.$i]['type'] == "image/pgif"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height); $imgdata = imagegif($thumb); } elseif($_FILES['image_'.$i]['type'] == "image/png" || $_FILES['image_'.$i]['type'] == "image/ppng"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height); $imgdata = imagepng($thumb); } if(!empty($imgdata)){ $fields_string[] = "Image_".$i; $fields_string[] = "Image_type_".$i; $insert_string[] = "'".mysql_real_escape_string($imgdata)."'"; $insert_string[] = $_FILES['image_'.$i]['type']; $update_string[] = "Image_".$i." = '".mysql_real_escape_string($imgdata)."'"; $update_string[] = "Image_type_".$i." = '".$_FILES['image_'.$i]['type']."'"; unset($im); unset($thumb); unset($imgdata); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433313 Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 well I'm trying to resize on upload but the imagecreatefromstring is failing any ideas? the error is Warning: getimagesize(Resource id #7) [function.getimagesize]: failed to open stream: No such file or directory in on line 34 and line 34 is the getimagesize line I don't know why its saying Resource id #7 when I echo it out it looks like binary junk. <?php $im = file_get_contents($_FILES['image_'.$i]['tmp_name'], FILE_BINARY); $im = imagecreatefromstring($im); list($width, $height) = getimagesize($im); $target = 150; if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } $width1 = round($width * $percentage); $height1 = round($height * $percentage); if($_FILES['image_'.$i]['type'] == "image/jpg" || $_FILES['image_'.$i]['type'] == "image/pjpg"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height) or die("error copyresize"); $imgdata = imagejpeg($thumb); } elseif($_FILES['image_'.$i]['type'] == "image/gif" || $_FILES['image_'.$i]['type'] == "image/pgif"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height); $imgdata = imagegif($thumb); } elseif($_FILES['image_'.$i]['type'] == "image/png" || $_FILES['image_'.$i]['type'] == "image/ppng"){ $thumb = ImageCreateTrueColor($width1, $height1); $thumb = imagecopyresized($thumb, $im, 0, 0, 0, 0, $width1, $height1, $width, $height); $imgdata = imagepng($thumb); } if(!empty($imgdata)){ $fields_string[] = "Image_".$i; $fields_string[] = "Image_type_".$i; $insert_string[] = "'".mysql_real_escape_string($imgdata)."'"; $insert_string[] = $_FILES['image_'.$i]['type']; $update_string[] = "Image_".$i." = '".mysql_real_escape_string($imgdata)."'"; $update_string[] = "Image_type_".$i." = '".$_FILES['image_'.$i]['type']."'"; unset($im); unset($thumb); unset($imgdata); } ?> getimagesize(string filename) where as we are trying to pass resource not a valid string 'filename' to the function.the parameter is not correct.Secondly if you try to give the $_FILE['image_'.$i]... it will return the correct image information. Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433323 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 it can't create the image from the string its at down error on the getsize the issue is that imagecreatefromstring(file_get_contents($_FILES['image_'.$i]['tmp_name']), FILE_BINARY)); is not working for some strange reason because when i do echo file_get_contents($_FILES['image.....); it echos out the binaries into the page like I figure it would. Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433324 Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 try the below code $f=file_get_contents($_FILES['uploadedfile']['tmp_name']); $im = imagecreatefromstring($f); $width = imagesx($im); $height = imagesy($im); $thumb = imagecreate($width,$height); imagecopyresized($thumb, $im, 0, 0, 0, 0, $width,$height,$width,$height) or die("error copyresize"); imagejpeg($thumb,'new_img.jpg'); regards Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433369 Share on other sites More sharing options...
PFMaBiSmAd Posted January 8, 2008 Share Posted January 8, 2008 The FILE_BINARY flag is php6 specific. Unless you are using php6, that likely results in an error. Check your web server log for errors any time code does not work as expected. Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433374 Share on other sites More sharing options...
cooldude832 Posted January 8, 2008 Author Share Posted January 8, 2008 I just gave up because I figured out that what I was doing couldn't work the way I thought so I just uploaded to a file, maybe later on i'll build a cron to transfer from there to the table. Didn't know that was a php6 only flag, but it also didn't error Quote Link to comment https://forums.phpfreaks.com/topic/84968-getting-the-content-of-a-uploaded-file/#findComment-433717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.