Jump to content

Problems with image upload


envexlabs

Recommended Posts

what's the error say?

 

could you show us the snippet of code that gives that error?

 

did you write the script or did you find it online somewhere? My guess is that the script is only set to work for .jpg or .gif images and data coming from a camera is either in raw format or has lots of extra meta data that the script can't handle.

if(empty($_FILES['pic']['name'])){}else{
//$ext = explode('.', $_FILES['pic']['name']);

//puts the array into a variable so that it can be inputed into the database as a name.ext instead of Array[]
$name = $_SESSION['username'] . '_' . $_FILES['pic']['name'];

//sets the directory and name for the file
$uploaddir = 'profile_pics/';
$uploadfile = $uploaddir . $name;

    
if (move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile)) 
{} 
else {
    echo "Picture could not be uploaded";
}
        
//changes the permissions of the file
//chmod($uploadfile, 0777);
                
$pic = $uploadfile;
                
//this shrinks the image if the orignal is too big
$org_size = getimagesize('http://www.yournightyourcity.com/' . $pic);

//takes the larger size of the width and height and applies the  
//formula accordingly...this is so this script will work  
//dynamically with any size image

$mywidth = $org_size[0];
$myheight = $org_size[1];
$target = 230;
$percentage = ($target / $mywidth);

//gets the new value and applies the percentage, then rounds the value
$mywidth = round($mywidth * $percentage);
$myheight = round($myheight * $percentage);

$source_path = $pic;
$destination_path = $pic;

$ext = strrchr($pic, ".");

$new_width= $mywidth;  //Image width Change if needed
$new_height= $myheight;  //Image height Change if needed
$destimg=imagecreatetruecolor($new_width,$new_height) or die("Problem In Creating image");

switch($ext) {
    case '.gif':
    $srcimg = imagecreatefromgif($pic) or die("Problem In opening Source Image");
    break;
    case '.jpg':
    $srcimg = imagecreatefromjpeg($pic) or die("Problem In opening Source Image");
    break;
    case '.jpeg':
    $srcimg = imagecreatefromjpeg($pic) or die("Problem In opening Source Image");
    break;
    case '.png':
    $srcimg = imagecreatefrompng($pic) or die("Problem In opening Source Image");
    break;
}

ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing");
Imagejpeg($destimg,$destination_path,100) or die("Problem In saving");

$org = 'profile_pics/'.$name;
$thumb = 'profile_pics/thumbs/'.$name;
$front_thumb = 'profile_pics/front_thumbs/'.$name;

$updatepic = mysql_query('UPDATE `member_info` SET `pic` = \'' . $pic . '\' WHERE `mem_id` = ' . $_POST['mem_id'] . '');

	$matt_ext = explode('.', $ext);

	//creates memberpage thumb
	cropImage(125, 150, $org, $matt_ext[1], $thumb);

	//creates frontpage thumb
	cropImage(135, 105, $org, $matt_ext[1], $front_thumb);

	//changes permissions for all images
	chmod($pic, 0755);
	chmod($thumb, 0755);
	chmod($front_thumb, 0755);

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.