Posts

Showing posts from December, 2012

How to upload a file in php with php validation of extension?

Simply copy and paste this code on your page And your input file name will be uploadedfile Like <input type="file" name="uploadedfile" /> and on submit of this page you will add this code $youruniqueid could be anything like userid or projected on the basis of this it will create folder for image upload $projId=$youruniqueid;    if(!empty($_FILES['uploadedfile']['name'])){     $imgExtension = array("jpg","jpe","jpeg","gif","png","GIF","JPG","JPEG","txt","pdf","PDF","docx","xlsx","pptx","pptm","doc","dot","xls","ppt");         $image_name = pathinfo($_FILES['uploadedfile']['name']);     $extension = strtolower($image_name['extension']);         if(in_array($extension,$imgExtension)){             $file_name = $_FILES['uplo

How to make a download link for download file in php

How to make a download link for download file in php or create a download link for download file in php? so here is the code and add base url according to your need   Create a php file download.php and paste this code in you php file $name = $_REQUEST['name']; // The file path where the file exists $filepath = 'http://www.site.com/files/'.$name; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //setting content type of page header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".basename($filepath )); header("Content-Description: File Transfer"); //Read File it will start downloading @readfile($filepath); Now add this link in your file on your anchor tag like <a href=" http://www.site.com/download.php?name=file.png " >download link</a>

How to get date from a timestamp in mysql?

Image
How to get date from a timestamp in mysql? simple you can use FROM_UNIXTIME function and pass the parameter. my table name is  messages like this: SELECT FROM_UNIXTIME(`created`,'%Y-%m-%d') as date FROM `messages`

How to create thumb image of uploaded image in php?

Simply copy and paste this code in your page and call generate_thumbimage_thumbnail() somthing like that $path  = 'uploadediamgepath/myimage.png'; $save_path2  = 'project_image_thumb/thumb__myimage.png'; $iscopied2 = copy($path , $save_path2); if($iscopied2){ generate_image_thumbnail($path, $save_path2); } function generate_thumbimage_thumbnail($source_image_path, $thumbnail_image_path) { define('THUMBNAIL_IMAGE_MAX_WIDTH', 130); define('THUMBNAIL_IMAGE_MAX_HEIGHT', 130); 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_imag