sivle
asked on
Using chmod with PHP to change file permissions after/during upload of images
OK...not sure if i'm providing enough information or not, but hopefully someone can help me. When I upload images to a directory, the default permissions are set to 600 on the files themselves. The directory has 777 permissions. I want to make my images readable and give them either 666 or 644 permisssion. Either would work. I suppose I need to somehow chmod the image files during upload or just after. Here is my code snippet that handles the image upload. I'm just not sure how to implement the needed change.
/***start****/
if ( $_FILES['bgimg']['name'] && !$_POST['bgdel'] )
{
if ( strlen($custom_arr['Backgr oundFilena me']) && file_exists($dir['profileB ackground' ] . $custom_arr['BackgroundFil ename']) && is_file($dir['profileBackg round'] . $custom_arr['BackgroundFil ename']) )
@unlink($dir['profileBackg round'] . $custom_arr['BackgroundFil ename']);
srand(time());
$pic_name = $ID . '_bg_' . rand(100, 999);
if ( !is_int($ext = moveUploadedImage( $_FILES, 'bgimg', $dir['profileBackground'] . $pic_name, '',false) ) )
{
if ( !$record_created )
{
$query = "INSERT INTO ProfilesSettings (`IDMember`, `BackgroundFilename` ) VALUES ( '$ID', '$pic_name$ext' )";
$record_created = 'ok';
}
else
{
$query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '$pic_name$ext', `Status` = 'Approval' WHERE `IDMember` = '$ID'";
}
$res = db_res( $query );
}
}
else if ( $_POST['bgdel'] )
{
if ( $custom_arr['BackgroundFil ename'] )
{
if (file_exists($dir['profile Background '] . $custom_arr['BackgroundFil ename'])) unlink($dir['profileBackgr ound'] . $custom_arr['BackgroundFil ename']);
$query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '' WHERE `IDMember` = '$ID'";
$res = db_res( $query );
}
}
/**** end ****/
/***start****/
if ( $_FILES['bgimg']['name'] && !$_POST['bgdel'] )
{
if ( strlen($custom_arr['Backgr
@unlink($dir['profileBackg
srand(time());
$pic_name = $ID . '_bg_' . rand(100, 999);
if ( !is_int($ext = moveUploadedImage( $_FILES, 'bgimg', $dir['profileBackground'] . $pic_name, '',false) ) )
{
if ( !$record_created )
{
$query = "INSERT INTO ProfilesSettings (`IDMember`, `BackgroundFilename` ) VALUES ( '$ID', '$pic_name$ext' )";
$record_created = 'ok';
}
else
{
$query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '$pic_name$ext', `Status` = 'Approval' WHERE `IDMember` = '$ID'";
}
$res = db_res( $query );
}
}
else if ( $_POST['bgdel'] )
{
if ( $custom_arr['BackgroundFil
{
if (file_exists($dir['profile
$query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '' WHERE `IDMember` = '$ID'";
$res = db_res( $query );
}
}
/**** end ****/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
see http://www.php.net/manual/en/function.chmod.php for more information
ASKER
Thanks, that's what i needed.
sivlE
sivlE