Jump to content

Recommended Posts

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

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);

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);
}
?>

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);
				}
?>

 

 

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.

 

 

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.

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

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

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.