0

I am uploading files with the following code using Bootstrap as my front-end framework.

<form method="POST" enctype="multipart/form-data" action= "php/up-load.php" role="form"
  <div class="form-group"> 
    <label for="file" class="col-sm-5 control-label">
      Select file(Compressed format)
    </label>
    <div>
      <input type="hidden" name="MAX_FILE_SIZE" value="1000000000"/>
      <input type="file" id="file" name="file" accept=".zip, .rar"/> 
    </div>
  </div>
  <div>                                                           
    <button type="submit" class="btn btn-primary" name="upload" id="upload">Send</button>
  </div>
</form>

My php code is;

@ $original=$_FILES['file']['name'];
@ $kiss=pathinfo($original, PATHINFO_EXTENSION);

$allowed_extensions = array(".zip","rar","bzip2","iso","gz","rz","7z","tar","tgz","bz2","tbz2","lzma","tlz");

$result = in_array ("$kiss", $allowed_extensions);

if (!$result)
{
  // Wrong file type
}
else
{
  //proceed..
}

My problem is that the

$_FILES['file']['name'];

is returning gibberish such as php7vy8X9 and phpY8wQVR . Have tried everything. What could be the problem?

Albzi
  • 15,431
  • 6
  • 46
  • 63
  • 1
    It's temporary file-name given by php. What you expecting ? – Rikesh Mar 18 '14 at 08:51
  • 3
    Do you mean `name` or `tmp_name`? – Álvaro González Mar 18 '14 at 08:52
  • $_FILES['file']['name'] This will return you the file name. These kind of names may be in tmp_name. for more please check this tutorial http://www.w3schools.com/php/php_file_upload.asp – Abdul Rauf Mar 18 '14 at 08:57
  • 1
    you didn't close:
    and maybe you can take a look at: http://stackoverflow.com/questions/22236035/insert-picture-into-database-using-php/22236798#22236798
    – SuperDJ Mar 18 '14 at 09:04

1 Answers1

0

$_FILES["file"]["name"] should be returning the original name of your file, what you are reporting should be stored inside $_FILES["file"]["tmp_name"]

The whole $_FILES array should look like this:

echo $_FILES["file"]["name"]; // Original Name
echo $_FILES["file"]["tmp_name"]; // Name (and location) given to the file by PHP
echo $_FILES["file"]["type"]; // File/mime type
echo $_FILES["file"]["size"]; // Total bytes
echo $_FILES["file"]["error"]; // Any error code which is returned during transfer
Jamie Taylor
  • 4,709
  • 5
  • 44
  • 66