List all uploaded file with Delete option

Hello guys,

Today, one of my friend asked me to display the uploaded files from folder with delete option. so i write below code, which i gonna share with u people.

list_file_with_del_option

so here, i’m creating delete button for each file with unique id(filename), when user press on button i’m passing id(filename) to del() function.
so in javascript, del() function i’m getting filename and that name i’m sending to delete.php file through ajax post method.

now let’s have a look on delete.php

delete

in this file, i’m checking whether $fname is file-name or directory-name. if it is file name then i’m deleting that particular file using unlink() function otherwise one error message will display to end user.

Note:  you must have test folder in your current directory if you are following this same code. otherwise you can change name of your whatever folder-name.

hope you all like this !

🙂

Avoiding the PHP GIF Security Issue

PHP GIF security Issue
sometime hacker can add php-code in the middle of GIF image. and they can hack some confidential information from your site.
usually uploading files are moved to given directory. so in form of image hacker will send some code in that directory and if site serves images directory from that directory, then  your site may be open for security exploits.

for ex, let’s say hacker upload an image named test.gif.php the image may be moved to the images directory.if webserver is configured as usaual to process request with .php file, and the site server the images with below url, the request will execute the php code inside that image file.
http://www.yoursite.com/test.gif.php

how to avoid?

basic solution to avoid this problem is to protect upload directory to avoid direct request to where images are located.

so you can fix it by editing .htaccess file.

code
<Files images>
deny from all
</Files>

and alternative solution is add php function to check valid file(image) extension.
please visit the previous post to learn that code.
https://webdevsurya.wordpress.com/2013/01/09/image-upload-validation-using-php/

have a nice DaY 🙂

Auto Complete Form Field

hello guys,

i found easy way to create auto-complete field. actually this is HTML5 feature,  you can use list attribute in your input type which is associated with datalist that renders autocomplete while people are typing in that field.

so here is simple code!

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>HTML5 Form Input Autocomplete datalist</h2>
Search State:
<input type=”text” name=”srch” id=”srch” list=”datalist1″ />
<datalist id=”datalist1″>
<option value=”gujarat”>
<option value=”karnataka”>
<option value=”panjab”>
<option value=”rajasthan”>
</datalist>
</body>
</html>

Done 🙂

Playing with Dates

while developing e-commerce project i got requirement like if any user purchase free trail product our website send one link to him which is limited for 3 days,so after 3 days if user click on that link it will show a message like “Your link has been expire”.

so first thing we need to create future date. below function help to create future date.

$limit_date = mktime(0,0,0,date("m"),date("d")+3,date("Y"));

next thing we need to think is how to compare two dates?

we can not directly use comparison operator for dates, so we need to use bellow function

The strtotime() function parses an English textual date or time into a Unix time stamp.

$cdate = date("Y-m-d");
$d1 = strtotime($cdate);
$d2 = strtotime($limitdate);
if($d1 > $d2)
{
	echo "limit over";
}

Done!!..!!  🙂