public function profileimageresizeandcopy($sourcedirec, $destinationdirec, $filename) { $id = Yii::app()->session['login']['id']; $model = UserProfile::model()->findByAttributes(array('user_id' => $id)); if (file_exists($sourcedirec)) { $destination = Yii::getPathOfAlias('webroot') . '/images/uploads/profileimages/thumbs/' . $filename; //$this->generatethumb($sourcedirec,$destination,120,120); FinaoController::generatethumb($sourcedirec, $destination, 120, 120); } if (copy($sourcedirec, $destinationdirec)) { if ($model->profile_image != "") { if (file_exists(Yii::app()->basePath . "/../images/uploads/profileimages/" . $model->profile_image)) { unlink(Yii::app()->basePath . "/../images/uploads/profileimages/" . $model->profile_image); } } $model->profile_image = $filename; if ($model->save(false)) { if (file_exists(Yii::app()->basePath . "/../images/uploads/temp_profileimages/" . $model->temp_profile_image)) { unlink(Yii::app()->basePath . "/../images/uploads/temp_profileimages/" . $model->temp_profile_image); } } if (isset(Yii::app()->session['login'])) { $login = Yii::app()->session['login']; $login["profImage"] = $filename; Yii::app()->session['login'] = $login; } } }
public static function actionfinaopreupload() { /************************************************************** * This script is brought to you by Vasplus Programming Blog * Website: www.vasplus.info * Email: info@vasplus.info ****************************************************************/ $upload_location = Yii::app()->basePath . '/../images/uploads/finaoimages/'; if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { $name = $_FILES['vasPhoto_uploads']['name']; $size = $_FILES['vasPhoto_uploads']['size']; //if(isset(Yii::app()->session['login']['filename'])) //unset(Yii::app()->session['login']['filename']); $allowedExtensions = array("jpg", "jpeg", "gif", "png"); //Allowed file types foreach ($_FILES as $file) { if ($file['tmp_name'] > '' && strlen($name)) { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { echo '<div class="info" style="width:370px;">Sorry, you attempted to upload an invalid file format. <br>Only jpg, jpeg, gif and png image files are allowed. Thanks.</div>'; } else { // if($size<(1024*1024)) // { $actual_image_name = Yii::app()->session['login']['id'] . '-' . rand(125678, 00) . '-' . $name; if (isset(Yii::app()->session['filename'])) { unset(Yii::app()->session['filename']); } Yii::app()->session['filename'] = $actual_image_name; // This could be a random name such as rand(125678,098754).'.gif'; /*$filename = substr(strrchr(Yii::app()->session['login']['id'].'-'.rand(125678,098754).'-'.$name,'/'),1); */ if (move_uploaded_file($_FILES['vasPhoto_uploads']['tmp_name'], $upload_location . $actual_image_name)) { if (file_exists(Yii::getPathOfAlias('webroot') . '/images/uploads/finaoimages' . '/' . $actual_image_name)) { $source = Yii::getPathOfAlias('webroot') . '/images/uploads/finaoimages' . '/' . $actual_image_name; $destination = Yii::getPathOfAlias('webroot') . '/images/uploads/finaoimages/thumbs' . '/' . $actual_image_name; $destination1 = Yii::getPathOfAlias('webroot') . '/images/uploads/finaoimages/medium' . '/' . $actual_image_name; $ext = substr(strrchr(Yii::getPathOfAlias('webroot') . '/images/uploads/finaoimages' . '/' . $actual_image_name, '.'), 1); FinaoController::generatethumb($source, $destination, 90, 90); FinaoController::generatethumb($source, $destination1, 240, 240); } //Run your SQL Query here to insert the new image file named $actual_image_name if you deem it necessary echo '<div style="width:370px; padding:10px 20px; height:245px; text-align:center; border:5px solid #E2E2E2; -moz-box-shadow: 0 0 5px #888; -webkit-box-shadow: 0 0 5px#888;box-shadow: 0 0 5px #888;"><span class="uploadeFileWrapper"><img id="filename" src="http://' . $_SERVER['HTTP_HOST'] . '/images/uploads/finaoimages/' . $actual_image_name . '" width="360" height="235"></span> </div> '; } else { echo "<div class='info' style='width:370px;'>Sorry, Your Image File could not be uploaded at the moment. <br>Please try again or contact the site admin if this problem persist. Thanks.</div>"; } // } // else // { // echo "<div class='info' style='width:345px;'>File exceeded 1MB max allowed file size. <br>Please upload a file at 1MB in size to proceed. Thanks.</div><br clear='all' />"; // } } } else { echo '<span class="uploadeFileWrapper"><img id="filename" src="http://' . $_SERVER['HTTP_HOST'] . '/images/uploads/finaoimages/' . Yii::app()->session[filename] . '" width="360" height="235"></span><br clear="all" />'; // echo "<div class='info' style='width:345px;'>You have just canceled your file upload process. Thanks.</div><br clear='all' />"; } } } }