Tag Archives: file

Filesystem functions

  • basename – It returns trailing name component of path
  • chgrp – It can be used to change file group
  • chmod – It can be used to change file permission
  • chown – It can be used to change file ownership
  • clearstatcache – It can be used to clears file status cache
  • copy – It can be used to copy file
  • delete – Check unlink() or unset()
  • dirname – It returns parent directory’s path
  • disk_free_space – It returns available space on filesystem or disk partition
  • disk_total_space – It returns the total size of a filesystem or disk partitio
  • diskfreespace – Its an alias of disk_free_space()
  • fclose – It closes an open file pointer
  • feof – It checks for end-of-file on a file pointer
  • fflush – It flushes the output to a file
  • fgetc – It returns character from file pointer
  • fgetcsv – It returns line from file pointer and parse for CSV fields
  • fgets – It returns line from file pointer
  • fgetss – It returns line from file pointer and strip HTML tags
  • file_exists – It checks whether a file or directory exists
  • file_get_contents – It reads entire file
  • file_put_contents – It writes a string to a file
  • file – It reads entire file into an array
  • fileatime – It returns last access time of file
  • filectime – It returns inode change time of file
  • filegroup – It returns file group
  • fileinode – It returns file inode
  • filemtime – It returns file modification time
  • fileowner – It returns  file owner
  • fileperms – It returns  file permissions
  • filesize – It returns  file size
  • filetype – It returns  file type
  • flock – It can be used to lock the file
  • fnmatch – Match filename against a pattern
  • fopen – It opens file or URL
  • fpassthru – It outputs all remaining data on a file pointer
  • fputcsv – It format line as CSV and write to file pointer
  • fputs – Its an  alias of fwrite() and writes to a file
  • fread – It can be used to read the content from a file
  • fscanf – It parses input from a file according to a format
  • fseek – It seeks on a file pointer
  • fstat – It returns information about a file using an open file pointer
  • ftell – It returns the current position of the file pointer
  • ftruncate – It truncates a file to a given length
  • fwrite – It writes the string to a file
  • glob – It finds pathnames matching a pattern
  • is_dir – It checks whether the filename is a directory
  • is_executable – It checks whether the filename is executable
  • is_file – It checks whether the filename is a regular file
  • is_link – It checks whether the filename is a symbolic link
  • is_readable – It checks whether the file exists and is readable
  • is_uploaded_file – It checks whether the file was uploaded via HTTP POST
  • is_writable – It checks whether  the filename is writable
  • is_writeable – Its an Alias of is_writable() and  checks whether  the filename is writable
  • lchgrp – It changes group ownership of symlink
  • lchown – It changes user ownership of symlink
  • link – It creates a hard link
  • linkinfo – It returns information about a link
  • lstat – It returns information about a file or symbolic link
  • mkdir – It can be used to create directory
  • move_uploaded_file – It moves an uploaded file to a new location
  • parse_ini_file – It parses a configuration file
  • parse_ini_string – It parse a configuration string
  • pathinfo – It returns information about a file path
  • pclose – It closes process file pointer
  • popen – It opens process file pointer
  • readfile – It outputs a file
  • readlink – It returns the target of a symbolic link
  • realpath_cache_get – It returns realpath cache entries
  • realpath_cache_size – It returns realpath cache size
  • realpath – It returns canonicalized absolute pathname
  • rename – It renames a file or directory
  • rewind – It rewinds the position of a file pointer
  • rmdir – It can be used to remove a directory
  • set_file_buffer – Its an alias of stream_set_write_buffer()
  • stat – It returns information about a file
  • symlink – It creates a symbolic link
  • tempnam – It create file with unique file name
  • tmpfile – It creates a temporary file
  • touch – It sets access and modification time of file
  • umask – It changes file permissions of file
  • unlink – It deletes the file

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>

File upload – PHP

<?php

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

if($_FILES[‘uploadFile’][‘name’]!=””) {

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

$name_img = substr(md5(uniqid(rand(),1)),0,32);

$uploadFile =”uploads/”.$name_img.”.”.$ext;

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

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

$success=5;

}else{

$errorList[]=”Select the file.”;

}

}

?>

<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>Select file</td> <td><input name=”uploadFile” type=”file”  /> 85×21</td> </tr> <tr> <td>&nbsp;</td> <td><input name=”upload” type=”submit”  value=”   Upload   ”  /> </td>

</tr>

</table>

</form>