Hallo,
Ik ben bezig met een soort marktplaats script en daarvoor zorg ik dat je 3 foto's kan uploaden:
PHP
if (isset($_POST['file1'])){
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file1"]["name"]);
$extension = end($temp);
if ((($_FILES["file1"]["type"] == "image/gif")
|| ($_FILES["file1"]["type"] == "image/jpeg")
|| ($_FILES["file1"]["type"] == "image/jpg")
|| ($_FILES["file1"]["type"] == "image/pjpeg")
|| ($_FILES["file1"]["type"] == "image/x-png")
|| ($_FILES["file1"]["type"] == "image/png"))
&& in_array($extension, $allowedExts)){
if ($_FILES["file1"]["error"] > 0){
echo 112;
} else {
echo 1;
$url1 = 'upload/'.$ran1.''.$_FILES["file1"]["name"].'';
move_uploaded_file($_FILES["file1"]["tmp_name"],
"upload/" . $ran1 . $_FILES["file1"]["name"]);
}
} else {
echo 2;
}
}
if (isset($_POST['file2'])){
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file2"]["name"]);
$extension = end($temp);
if ((($_FILES["file2"]["type"] == "image/gif")
|| ($_FILES["file2"]["type"] == "image/jpeg")
|| ($_FILES["file2"]["type"] == "image/jpg")
|| ($_FILES["file2"]["type"] == "image/pjpeg")
|| ($_FILES["file2"]["type"] == "image/x-png")
|| ($_FILES["file2"]["type"] == "image/png"))
&& ($_FILES["file2"]["size"] < 20000)
&& in_array($extension, $allowedExts)){
if ($_FILES["file2"]["error"] > 0){
} else {
$url2 = 'upload/'.$ran2.''.$_FILES["file2"]["name"].'';
move_uploaded_file($_FILES["file2"]["tmp_name"],
"upload/" . $ran2 . $_FILES["file2"]["name"]);
}
}
}
if (isset($_POST['file3'])){
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file3"]["name"]);
$extension = end($temp);
if ((($_FILES["file3"]["type"] == "image/gif")
|| ($_FILES["file3"]["type"] == "image/jpeg")
|| ($_FILES["file3"]["type"] == "image/jpg")
|| ($_FILES["file3"]["type"] == "image/pjpeg")
|| ($_FILES["file3"]["type"] == "image/x-png")
|| ($_FILES["file3"]["type"] == "image/png"))
&& ($_FILES["file3"]["size"] < 20000)
&& in_array($extension, $allowedExts)){
if ($_FILES["file3"]["error"] > 0){
} else {
$url3 = 'upload/'.$ran3.''.$_FILES["file3"]["name"].'';
move_uploaded_file($_FILES["file3"]["tmp_name"],
"upload/" . $ran3 . $_FILES["file3"]["name"]);
}
}
}
Toon Meer
Maar omdat dit niet werkt ben ik gaan debuggen met het bovenste stukje:
PHP
if (isset($_POST['file1'])){
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file1"]["name"]);
$extension = end($temp);
if ((($_FILES["file1"]["type"] == "image/gif")
|| ($_FILES["file1"]["type"] == "image/jpeg")
|| ($_FILES["file1"]["type"] == "image/jpg")
|| ($_FILES["file1"]["type"] == "image/pjpeg")
|| ($_FILES["file1"]["type"] == "image/x-png")
|| ($_FILES["file1"]["type"] == "image/png"))
&& in_array($extension, $allowedExts)){
if ($_FILES["file1"]["error"] > 0){
echo 112;
} else {
echo 1;
$url1 = 'upload/'.$ran1.''.$_FILES["file1"]["name"].'';
move_uploaded_file($_FILES["file1"]["tmp_name"],
"upload/" . $ran1 . $_FILES["file1"]["name"]);
}
} else {
echo 2;
}
}
Toon Meer
Maar ik snap niet waarom hij 2 echo't?
Alvast bedankt.