Hello guys,
I've written this code for my website so that I can upload pictures & attach description to the them. The problem is, it works fine for me (PC & phone), but whenever my friend tries to upload one himself, he gets an error (btw this is for cars). Could somebody please take a look at it, see if I'm doing something wrong, or maybe have a better suggestion for it? Thanks a bunch!
HTML:
<div id="main">
<form action="upload.php" method="POST" enctype="multipart/form-data">
<div class="clear">
<br><br>
<div class="col3">
<input type="file" name="file[]" id="browse" multiple required/><br />
</div>
<div class="col3">
<div id="brprev">Bitte eine Bild auswählen!</div>
<br />
</div>
<div class="col3">
<div class="inp">
<label>Hersteller</label> <input type="text" name="text1" required>
</div><br>
<div class="inp">
<label>Model</label> <input type="text" name="text2" required>
</div><br>
<div class="inp">
<label>Baujahr</label> <input type="text" name="text3" required>
</div><br>
<div class="inp">
<label>Km Stand</label> <input type="text" name="text4" required>
</div><br>
<div class="inp">
<label>PS / KW</label> <input type="text" name="text5" required>
</div><br>
<div class="inp">
<label>Kraftstoff</label> <input type="text" name="text6" required>
</div><br>
<div class="inp">
<label>Getriebe</label> <input type="text" name="text7" required>
</div><br>
<div class="inp">
<label>TÜV & AU</label> <input type="text" name="text8" required>
</div><br>
<div class="inp">
<label>Preis</label> <input type="text" name="text9" required>
</div><br>
<div class="inp">
<label>Beschreibung</label> <textarea name="text10" required></textarea>
</div><br>
<input type="submit" value="Hochladen" id="submit"/>
</div>
</div>
</form>
<br>
<br>
<form action="delete.php" method="POST">
Bild Nummer eintragen: <input type="text" name="delid" required> <input type="submit" value="Bild Löschen" id="submit"/>
</form>
PHP (upload):
<?php
if(!isset($_POST['text1'])||empty($_POST['text1'])) die("Hersteller not set!");
if(!isset($_POST['text2'])||empty($_POST['text2'])) die("Model not set!");
if(!isset($_POST['text3'])||empty($_POST['text3'])) die("Baujahr not set!");
if(!isset($_POST['text4'])||empty($_POST['text4'])) die("Km Stand not set!");
if(!isset($_POST['text5'])||empty($_POST['text5'])) die("Preis not set!");
$kcc=1;
$location = 'Images/';
$id = @file_get_contents($location.'c.txt')+1;
file_put_contents($location.'c.txt',$id);
$data = $_POST['text1']."\r\n";
$data.= $_POST['text2']."\r\n";
$data.= $_POST['text3']."\r\n";
$data.= $_POST['text4']."\r\n";
$data.= $_POST['text5']."\r\n";
$data.= $_POST['text6']."\r\n";
$data.= $_POST['text7']."\r\n";
$data.= $_POST['text8']."\r\n";
$data.= $_POST['text9']."\r\n";
$data.= str_replace("\n", '', $_POST['text10'])."\r\n";
$data.= sizeof($_FILES['file']['name']).'-images'."\r\n";
file_put_contents($location.$id.'.txt',$data);
foreach($_FILES['file']['name'] as $k=>$v){
$name = $_FILES['file']['name'][$k];
$size = $_FILES['file']['size'][$k];
$type = $_FILES['file']['type'][$k];
$extension = pathinfo($name, PATHINFO_EXTENSION);
$max_size = 20971520;
$tmp_name = $_FILES['file']['tmp_name'][$k];
$error = $_FILES['file']['error'][$k];
if (isset($name) && !empty($name)) {
if (($extension=='jpg' || $extension=='jpeg' || $extension=='png') && $size<=$max_size) {
move_uploaded_file($tmp_name, $location.$id.'_'.($kcc++).'.png');
echo 'Bild wird hochgeladen!<br>';
} else {
echo 'Bitte eine Bild auswählen!<br>';
}
} else {
echo 'Bild muss ein jpg/jpeg/png Typ sein und kleiner als 20mb!<br>';
}
}
?>
<script>
setTimeout(function(){
window.location.href = 'http://www.google.com';
}, 3000);
</script>
[Every image upload creates a '.txt' file in the folder "Images" where the info is stored]
PHP (delete):
<?php
$id = isset($_POST['delid'])?intval($_POST['delid']):0;
if($id){
if(file_exists('Images/'.$id.'.txt')){
$data = file('Images/'.$id.'.txt')[10];
unlink('Images/'.$id.'.txt');
for($i=1;$i<=$data;$i++){
if(file_exists('Images/'.$id.'_'.$i.'.png')) unlink('Images/'.$id.'_'.$i.'.png');
}
}elseif(file_exists('Images/'.$id.'_1.png')) unlink('Images/'.$id.'_1.png');
echo 'Bild wurde gelöscht!';
}
?>
<script>
setTimeout(function(){
window.location.href = 'http://www.google.com';
}, 3000);
</script>
I'd really appreciate your help!