PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,443 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,536 people online right now. Registration is fast and FREE... Join Now!




changing file permission on image upload

 

changing file permission on image upload

the_new_guy

29 Jun, 2009 - 02:28 AM
Post #1

New D.I.C Head
*

Joined: 15 May, 2009
Posts: 11


My Contributions
hello, i need to change the file permision on the file that gets saved in the following code but i don't know how to. it keeps saving as 655 but i need it to save the file with the permission 777. can anyone help??? thanks
CODE
<form action="imageclass.php" method="post" enctype="multipart/form-data">
    <p align="left"><br>
        <input name="Image1" type="file" size="50" />
          <span class="style9"></span> </p>
    <p align="left"><br>
        <input type="submit" value="Upload Photo">
    </p>
  </form>
CODE
<?php
//--------------------------------
// CREATE WATERMARK FUNCTION
//--------------------------------

define( 'THUMBNAIL_IMAGE_MAX_WIDTH', 150 );
define( 'THUMBNAIL_IMAGE_MAX_HEIGHT', 150 );

function generate_image_thumbnail( $source_image_path, $thumbnail_image_path )
{
  list( $source_image_width, $source_image_height, $source_image_type ) = getimagesize( $source_image_path );

  switch ( $source_image_type )
  {
   case IMAGETYPE_GIF:
    $source_gd_image = imagecreatefromgif( $source_image_path );
    break;

   case IMAGETYPE_JPEG:
    $source_gd_image = imagecreatefromjpeg( $source_image_path );
    break;

   case IMAGETYPE_PNG:
    $source_gd_image = imagecreatefrompng( $source_image_path );
    break;
  }

  if ( $source_gd_image === false )
  {
   return false;
  }

  $thumbnail_image_width = THUMBNAIL_IMAGE_MAX_WIDTH;
  $thumbnail_image_height = THUMBNAIL_IMAGE_MAX_HEIGHT;

  $source_aspect_ratio = $source_image_width / $source_image_height;
  $thumbnail_aspect_ratio = $thumbnail_image_width / $thumbnail_image_height;

  if ( $source_image_width <= $thumbnail_image_width && $source_image_height <= $thumbnail_image_height )
  {
   $thumbnail_image_width = $source_image_width;
   $thumbnail_image_height = $source_image_height;
  }
  elseif ( $thumbnail_aspect_ratio > $source_aspect_ratio )
  {
   $thumbnail_image_width = ( int ) ( $thumbnail_image_height * $source_aspect_ratio );
  }
  else
  {
   $thumbnail_image_height = ( int ) ( $thumbnail_image_width / $source_aspect_ratio );
  }

  $thumbnail_gd_image = imagecreatetruecolor( $thumbnail_image_width, $thumbnail_image_height );

  imagecopyresampled( $thumbnail_gd_image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $source_image_width, $source_image_height );

  imagejpeg( $thumbnail_gd_image, $thumbnail_image_path, 90 );

  imagedestroy( $thumbnail_gd_image );

  return true;
}

//--------------------------------
// FILE PROCESSING FUNCTION
//--------------------------------

define( 'UPLOADED_IMAGE_DESTINATION', './images/users/' );
define( 'THUMBNAIL_IMAGE_DESTINATION', './images/thumbnails/' );

function process_image_upload( $field )
{
  $temp_image_path = $_FILES[ $field ][ 'tmp_name' ];
  $temp_image_name = $_FILES[ $field ][ 'name' ];

  list( , , $temp_image_type ) = getimagesize( $temp_image_path );

  if ( $temp_image_type === NULL )
  {
   return false;
  }

  switch ( $temp_image_type )
  {
  

   case IMAGETYPE_JPEG:
    break;


   default:
    return false;
  }
  $userid = $_SESSION['MM_Username'];
  $uploaded_image_path = UPLOADED_IMAGE_DESTINATION . $userid .'.jpg';
  


  move_uploaded_file( $temp_image_path, $uploaded_image_path );

  $thumbnail_image_path = THUMBNAIL_IMAGE_DESTINATION. $userid . preg_replace( '{\\.[^\\.]+$}', '.jpg','.jpg' );

  $result = generate_image_thumbnail( $uploaded_image_path, $thumbnail_image_path );

  return $result
   ? array( $uploaded_image_path, $thumbnail_image_path )
   : false;
}

//--------------------------------
// END OF FUNCTIONS
//--------------------------------

$result = process_image_upload( 'Image1' );

if ( $result === false )
{
  echo '<br>An error occurred while processing upload';
}
else
{
  echo 'your photo was uploaded succsessfully';
  $filename = mysql_real_escape_string($row_listUsers['image']);
}
?>


User is offlineProfile CardPM
+Quote Post


noorahmad

RE: Changing File Permission On Image Upload

29 Jun, 2009 - 03:13 AM
Post #2

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
you can use chmode
php

chmod("directory/file.txt", 0600);

User is online!Profile CardPM
+Quote Post

the_new_guy

RE: Changing File Permission On Image Upload

1 Jul, 2009 - 05:37 AM
Post #3

New D.I.C Head
*

Joined: 15 May, 2009
Posts: 11


My Contributions
thanks., it works ok now. thanks again for your help
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: Changing File Permission On Image Upload

1 Jul, 2009 - 08:30 PM
Post #4

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
Your Welcome.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:30AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month