0

Now I am interested to provide a blogging service from my site and testing of it. I would like to allow users to upload only html, css, js, jpg, png, ico, gif, zip, pdf and mp3 files but I would not like to limit on size to upload.

Now I am testing my site on localhost but I did not get any reliable php script to upload file, somewhere it seems as if PHP doesn't allow to upload .ico image, .mp3 file and something loaded zip file as well.

I would not like to allow users to upload other extensions than specified ones but whatever they must be able to upload after making zip. Please help me..

I will thank you very much..

BenEgan1991
  • 637
  • 1
  • 9
  • 15
user3603684
  • 51
  • 1
  • 8
  • check [this](http://stackoverflow.com/questions/10456113/php-check-file-extension-in-upload-form) – Babu May 05 '14 at 09:46

1 Answers1

0

Your plugin must to load script.php and return a json here is an example :

// test if image or video
$img = strstr($_FILES["myfile"]["type"], "image");
$video = strstr($_FILES["myfile"]["type"], "video");

if($img) {
    $output_dir = "../images/";
}
elseif($video) {
    $output_dir = "../videos/";
}

if(isset($_FILES["myfile"]))
{
    $ret = array();
    $error = $_FILES["myfile"]["error"];

    if(!is_array($_FILES["myfile"]["name"])) {      // Only on file
        $fileName = $_FILES["myfile"]["name"];
        move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);
        $img_type = getImageSize("../images/".$_FILES["myfile"]["name"]);

        if(!$img_type) { // Si le contenu n'est pas une image
            unlink("../images/".$_FILES["myfile"]["name"]);
        }
        $ret[]= $fileName;
    }
    else {  // multiples files
      $fileCount = count($_FILES["myfile"]["name"]);

      for($i=0; $i < $fileCount; $i++) {
        $fileName = $_FILES["myfile"]["name"][$i];
        move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName);
        $ret[]= $fileName;
      }
    }
    var_dump($ret);
    echo json_encode($ret);
}
Dev'Hamz
  • 478
  • 4
  • 9