Category Archives: PHP

Persistent Cookie

Also called a permanent cookie, or a stored cookie, a cookie that is stored on a user s hard drive until it expires (persistent cookies are set with expiration dates) or until the user deletes the cookie.

Persistent cookies help websites remember your information and settings when you visit them in the future. This result in faster and more convenient access since, for example, you don’t have to login again.

Besides authentication, other website features made possible by persistent cookies include: language selection, theme selection, menu preferences, internal site bookmarks or favorites, among many others. On your first visit, the website is presented in default mode. During your visit, you select your preferences and these preferences are remembered, through the use of the persistent cookie, the next time you visit the site.

Multiple file upload – PHP

function addfileImages() {

document.getElementById(“totalfileImages”).value = Number(document.getElementById(“totalfileImages”).value) + Number(1);

if(Number(document.getElementById(“totalfileImages”).value)>Number(10)){ document.getElementById(“addButton”).style.display=”none”; document.getElementById(“totalfileImages”).value=10; }

document.getElementById(“fileImages”+document.getElementById(“totalfileImages”).value).style.display=”block”;

}

function removefileImages() {

document.getElementById(“fileImages”+document.getElementById(“totalfileImages”).value).style.display=”none”; document.getElementById(“totalfileImages”).value = Number(document.getElementById(“totalfileImages”).value) – Number(1);

if(Number(document.getElementById(“totalfileImages”).value)

<?php

if(isset($_POST[‘upload’])) {

extract($_POST);

for($i=1;$i<=$totalfileImages;$i++) {

if($_FILES[‘file_image’.$i][‘name’]!=””){

$ext =array_pop(explode(“.”,$_FILES[‘file_image’.$i][‘name’]));

$card_image =”uploads/”.substr(md5(uniqid(rand(),1)),0,32).”.”.$ext;

move_uploaded_file($_FILES[‘file_image’.$i][‘tmp_name’],$card_image) or die(“Could not upload!! make sure that uploads/is writable”);

chmod($card_image,0777) or die(“Could not change permission”);

$success=5;

}else{

$errorList[0]=”Upload all the files “;

} } }?>

<form action=”#” method=”post” enctype=”multipart/form-data”>

<table>

<?php if(count($errorList)>0){ ?>

<tr> <td>&nbsp;</td> <td>

</td> </tr>

<?php } ?>

<?php if($success==5){ ?>

<tr> <td>&nbsp;</td> <td>

File has been uploaded

</td> </tr>

<?php } ?>

<tr> <td valign=”top”>Select file</td> <td> <?php $maxFiles=10; ?>

<?php for($i=2;$i<=$maxFiles;$i++) { ?>

“>   ”  />Delete

<?php } ?>

<input type=”hidden” id=”totalfileImages”  name=”totalfileImages” value=”1″ /> </td>

</tr>

<tr> <td>&nbsp;</td> <td><input name=”upload” type=”submit”  value=”   Upload   ”  /> </td> </tr>

</table>

</form>