Ik heb een vraagje,
Momenteel heb ik een Html form waar een gebruiker meerdere foto's kan uploaden. Deze foto's worden via PHP geresized. Hierna wordt hij via move_uploaded_file verplaats naar de folder (images/). Maar hier gaat er iets mis.....want hij upload de foto's naar mijn root folder? Is er iemand die mij kan helpen bij de probleem?
Hier is mijn upload code:
$query = "SELECT id FROM ncr_input ORDER BY id DESC LIMIT 1";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_row($result);
$ncrnummer = $row[0];
for ($i = 0; $i < count($_FILES['attachments']['name']); $i++) {
$sourcefile = $_FILES['attachments']['tmp_name'][$i];
$endfile = $_FILES['attachments']['name'][$i];
$type = $_FILES['attachments']['type'][$i];
$filepath = "images/" . $endfile;
ResizePicture($sourcefile, $max_width = 500, $max_height = 500, $endfile, $type);
if (move_uploaded_file($endfile, $filepath)) {
$querypictureupload = "INSERT INTO file_upload(ncrnummer,filename) VALUES ('$ncrnummer','$endfile')";
$result = mysqli_query($conn, $querypictureupload);
}
else {
echo "Error";
}
}
Hier de code van mijn ResizePicture:
<?php
function ResizePicture($sourcefile,$max_width, $max_height, $endfile, $type){
switch($type){
case'image/png':
$img = imagecreatefrompng($sourcefile);
break;
case'image/jpeg':
$img = imagecreatefromjpeg($sourcefile);
break;
case'image/gif':
$img = imagecreatefromgif($sourcefile);
break;
default :
return 'Un supported format';
}
$width = imagesx( $img );
$height = imagesy( $img );
if ($width > $height) {
if($width < $max_width) {
$newwidth = $width;
}
else {
$newwidth = $max_width;
$divisor = $width / $newwidth;
$newheight = floor($height / $divisor);
}
}
else {
if($height < $max_height) {
$newheight = $height;
}
else {
$newheight = $max_height;
$divisor = $height / $newheight;
$newwidth = floor($width / $divisor);
}
}
$tmpimg = imagecreatetruecolor( $newwidth, $newheight );
imagealphablending($tmpimg, false);
imagesavealpha($tmpimg, true);
imagecopyresampled( $tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
switch($type){
case'image/png':
imagepng($tmpimg, $endfile, 0);
break;
case'image/jpeg':
imagejpeg($tmpimg, $endfile, 100);
break;
case'image/gif':
imagegif($tmpimg, $endfile, 0);
break;
}
imagedestroy($tmpimg);
imagedestroy($img);
}
?>
Extra vraagje: Hoe krijg ik mijn code een beetje fatsoenlijk, Zodat jullie het ook kunnen lezen
Op internet heb ik gezocht naar oplossingen,
Dit heb ik al geprobeerd:
is_writable($filepath) Hier komt uit dat deze gewoon bereikbaar is!
Momenteel heb ik een Html form waar een gebruiker meerdere foto's kan uploaden. Deze foto's worden via PHP geresized. Hierna wordt hij via move_uploaded_file verplaats naar de folder (images/). Maar hier gaat er iets mis.....want hij upload de foto's naar mijn root folder? Is er iemand die mij kan helpen bij de probleem?
Hier is mijn upload code:
$query = "SELECT id FROM ncr_input ORDER BY id DESC LIMIT 1";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_row($result);
$ncrnummer = $row[0];
for ($i = 0; $i < count($_FILES['attachments']['name']); $i++) {
$sourcefile = $_FILES['attachments']['tmp_name'][$i];
$endfile = $_FILES['attachments']['name'][$i];
$type = $_FILES['attachments']['type'][$i];
$filepath = "images/" . $endfile;
ResizePicture($sourcefile, $max_width = 500, $max_height = 500, $endfile, $type);
if (move_uploaded_file($endfile, $filepath)) {
$querypictureupload = "INSERT INTO file_upload(ncrnummer,filename) VALUES ('$ncrnummer','$endfile')";
$result = mysqli_query($conn, $querypictureupload);
}
else {
echo "Error";
}
}
Hier de code van mijn ResizePicture:
<?php
function ResizePicture($sourcefile,$max_width, $max_height, $endfile, $type){
switch($type){
case'image/png':
$img = imagecreatefrompng($sourcefile);
break;
case'image/jpeg':
$img = imagecreatefromjpeg($sourcefile);
break;
case'image/gif':
$img = imagecreatefromgif($sourcefile);
break;
default :
return 'Un supported format';
}
$width = imagesx( $img );
$height = imagesy( $img );
if ($width > $height) {
if($width < $max_width) {
$newwidth = $width;
}
else {
$newwidth = $max_width;
$divisor = $width / $newwidth;
$newheight = floor($height / $divisor);
}
}
else {
if($height < $max_height) {
$newheight = $height;
}
else {
$newheight = $max_height;
$divisor = $height / $newheight;
$newwidth = floor($width / $divisor);
}
}
$tmpimg = imagecreatetruecolor( $newwidth, $newheight );
imagealphablending($tmpimg, false);
imagesavealpha($tmpimg, true);
imagecopyresampled( $tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
switch($type){
case'image/png':
imagepng($tmpimg, $endfile, 0);
break;
case'image/jpeg':
imagejpeg($tmpimg, $endfile, 100);
break;
case'image/gif':
imagegif($tmpimg, $endfile, 0);
break;
}
imagedestroy($tmpimg);
imagedestroy($img);
}
?>
Extra vraagje: Hoe krijg ik mijn code een beetje fatsoenlijk, Zodat jullie het ook kunnen lezen

Op internet heb ik gezocht naar oplossingen,
Dit heb ik al geprobeerd:
is_writable($filepath) Hier komt uit dat deze gewoon bereikbaar is!