Uploaded images file permissions
Posted: Tue Aug 01, 2006 2:11 am
When I upload an image I am trying to resize it and do fun things with it. Well the upload works fine but it uploads it with permissions 411 which does not let me change the picture sizes and stuff. I have tried to chmod the tmp file AND the uploaded file right after I do the upload but to no avail. I know this has to be something with my code as I have been able to do this in the past. Here is my code:
and my DoResize function:
Code: Select all
foreach ($_FILES['Pictures']['error'] as $key => $error)
{
if (0 === $error)
{
$IM->Set('fkListingId', $ListingId);
$tmp = $_FILES['Pictures']['tmp_name'][$key];
$name = $_FILES['Pictures']['name'][$key];
while (file_exists($UploadDir.$name))
{
$name = str_replace(' ', '', microtime());
$name = str_replace('.', '', $name);
}
$DBPath = GetUserId().'/';
move_uploaded_file($tmp, $UploadDir.$name);
if (false === chmod($UploadDir.$name, '0777'))
{
die('unable to chmod file on line: '.__LINE__);
}
if ($key == $MakeThumb && true !== $MakeThumb)
{
$ImageResize->DoResize($UploadDir.$name, $UploadDir.'thumb_'.$name, 100, 100);
$IM->Set('Path', $DBPath.'thumb_'.$name);
$IM->Set('isThumb', 1);
$IM->Save();
}
else if (false === $MakeThumb)
{
$ImageResize->DoResize($UploadDir.$name, $UploadDir.'thumb_'.$name, 100, 100);
$MakeThumb = true;
$IM->Set('Path', $DBPath.'thumb_'.$name);
$IM->Set('isThumb', 1);
$Im->Save();
}
$ImageResize->DoResize($UploadDir.$name, $UploadDir.$name, 400, 300);
$IM->Set('Path', $DBPath.$name);
$IM->Set('isThumb', 0);
$IM->Save();
}
}Code: Select all
public function DoResize($src, $out, $outX, $outY)
{
$dim = @getimagesize($src);
if ($dim === FALSE)
{
trigger_error('Failed to read the source image', E_USER_ERROR);
}
list($srcX, $srcY, $srcType) = $dim;
switch ($srcType)
{
case 1:
$imgSrc = @imagecreatefromgif($src);
break;
case 2:
$imgSrc = @imagecreatefromjpeg($src);
break;
case 3:
$imgSrc = @imagecreatefrompng($src);
break;
default:
trigger_error('Unsupported image type', E_USER_ERROR);
}
$imgOut = @imagecreatetruecolor($outX, $outY);
if (false === $imgSrc || false === $imgOut)
{
trigger_error('Failed to create image', E_USER_ERROR);
}
if (false === @imagecopyresampled($imgOut, $imgSrc, 0, 0, 0, 0, $outX, $outY, $srcX, $srcY))
{
trigger_error('Failed to resize image', E_USER_ERROR);
}
switch ($srcType)
{
case 1:
$saveres = @imagegif($imgOut, $out);
break;
case 2:
$saveres = @imagejpeg($imgOut, $out);
break;
case 3:
$saveres = @imagepng($imgOut, $out);
break;
default:
trigger_error('Unsupported image type', E_USER_ERROR);
}
if (false === $saveres)
{
trigger_error('Failed to save image', E_USER_ERROR);
}
return true;
}