File upload – 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”);



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




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


<?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 } ?>


<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>






Leave a Reply

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