0

I have a problem running a script to upload a GIF image on my server. I'm using Windows Server 2012 and IIS 8. I tried in all the ways that I found on internet but it is still not working.

In my php.ini the upload temp. dir. is "C:\Windows\Temp" which has the full control permission. Is the same even for the final destination that you can see in this script:

if(isset($_POST['uploadform'])){
  $target_dir = "uploads/";
  $target_file = $target_dir . basename($_FILES["userfile"]["name"]);
  $nomefile = $_FILES["userfile"]["name"];
  $uploadOk = 1;
  $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  print_r($_FILES);
  // Check file size
  if ($_FILES["userfile"]["size"] > 15000000) {
    echo "Too big.";
    $uploadOk = 0;
  }

  // Check if $uploadOk is set to 0 by an error
  if ($uploadOk == 0) 
    echo "Sorry, your file was not uploaded.";
   else // if everything is ok, try to upload file
  if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_file)) 
    header("LOCATION: ". WEB ."/ok.php");
}

I have nothing with this code. In the php.ini the file uploading is enabled but nothing appears. Could you help me?

Thanks a lot!

Jehy
  • 4,729
  • 1
  • 38
  • 55
  • 1
    Did you enable error reporting in PHP? – Jehy Jun 01 '16 at 13:41
  • @Jehy yes, but nothing happens – giovanni256 Jun 01 '16 at 15:09
  • do you see printed $_FILES array? Also, try assigning variable to move_uploaded_file result and output error if it fails. – Jehy Jun 03 '16 at 08:35
  • I can see online "Array ( )" when I try to upload a file. What can I do? I set the Full control permissions to my temporary upload directory and also to the final destination, uploads/. @Jehy – giovanni256 Jun 03 '16 at 08:49
  • If your $_FILES is empty - it could be a problem with your HTML form. Does your form have `enctype="multipart/form-data"`? If yes - check also this thread: http://stackoverflow.com/questions/3586919/why-would-files-be-empty-when-uploading-files-to-php – Jehy Jun 03 '16 at 08:59
  • I also simplified your code (edited directly in question) a bit to avoid unneccessary brackets which make it harder to understand. Also, I added formatting. But it makes absolutely same things. – Jehy Jun 03 '16 at 09:08
  • I don't know why, but I forgot that! Thanks a lot my friend! – giovanni256 Jun 03 '16 at 09:31
  • you are welcome. I added this as an aswer so you can accept is a decision. – Jehy Jun 03 '16 at 09:55

1 Answers1

0

Problem was in HTML - don't forget to add enctype="multipart/form-data" to your files form.

Jehy
  • 4,729
  • 1
  • 38
  • 55