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><div style=”margin:5px; color:#FF0000;”><?php foreach($errorList as $value) echo $value.” ,”; ?></div></td> </tr>

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

<tr> <td>&nbsp;</td> <td><div style=”margin:10px; color: #006633; width:90%; font-weight:bold”>File has been uploaded</div></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>

 

One thought on “File upload – PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>