I use this script for uploading an image file. It should allow to upload jpeg, jpg and png files.
Everything works on remote server, but I can't upload it locally, on XAMPP server. I tried all tips mentioned in this thread Why would $_FILES be empty when uploading files to PHP? but no one worked.
Thanks for help
Form:
<form class="form-horizontal" action="potwierdz.php" method="POST" enctype="multipart/form-data">
<fieldset>
<!-- Form Name -->
<legend>Dodawanie produktu</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="produkt_nazwa">Nazwa</label>
<div class="col-md-4">
<input id="produkt_nazwa" name="produkt_nazwa" class="form-control input-md" required="" type="text">
<span class="help-block">Podaj nazwę produktu</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="producent_nazwa">Nazwa producenta</label>
<div class="col-md-4">
<input id="producent_nazwa" name="producent_nazwa" class="form-control input-md" required="" type="text">
<span class="help-block">Podaj nazwę producenta produktu</span>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="producent_adres">Adres producenta</label>
<div class="col-md-4">
<textarea class="form-control" id="producent_adres" name="producent_adres" required=""></textarea>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="produkt_kategoria_nazwa">Kategoria</label>
<div class="col-md-4">
<select id="produkt_kategoria_nazwa" name="produkt_kategoria_nazwa" class="form-control">
<option> </option>
</select>
</div>
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="obraz">Zdjęcie</label>
<div class="col-md-4">
<input id="obraz" name="obraz" class="input-file" type="file">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="wyslij"></label>
<div class="col-md-4">
<button id="wyslij" name="wyslij" class="btn btn-primary">Dodaj</button>
</div>
</div>
</fieldset>
</form>
here is script:
<?php
$errors= array();
$file_name = $_FILES['obraz']['name'];
$file_size =$_FILES['obraz']['size'];
$file_tmp =$_FILES['obraz']['tmp_name'];
$file_type=$_FILES['obraz']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['obraz']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"obrazki/".$file_name);
echo "Success";
}else{
print_r($errors);
}
?>
It returns me "extension not allowed, please choose a JPEG or PNG file."
It's also printing
Notice: Undefined index: obraz
whenever I use $_FILES['obraz']['...']
variable.