I recently attempted to add a server side handler for dropzone.js and followed this video as I know little to no PHP: https://www.youtube.com/watch?v=QVEv62wKbOc
I added all the script, but when I click "View Upload" it prints out ""; } } } echo $output;" in a blank page. Also, even though the animation of the file being uploaded is successful, the file never ends up on the "uploads" folder. (It's supposed to preview all of the uploaded pictures instead, as shown in the video on 9:32 on the video)
Below is everything I added. (Not including the dropzone.js & dropzone.css files as they have no changes made) It is currently being hosted on a localhost.
parser.php:
<?php
if(!empty($_FILES)){
$temp = $_FILES['file']['tmp_name'];
$dir_separator = DIRECTORY_SEPARATOR;
$folder = "uploads";
$destination_path = dirname(__FILE__).$dir_separator.$folder.$dir_separator;
$target_path = $destination_path.$_FILES['file']['name'];
move_uploaded_file($temp, $target_path);
} ?>
view_upload.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Upload</title>
</head>
<body>
<?php
$folder = "uploads";
if(is_dir($folder)){
$handler = opendir($folder);
$output = "";
while($files = readdir($handler)){
if(!is_dir($files)){
$output .= "<img src=\"uploads/{$files}\" width='180' height='180'>";
}
}
}
echo $output; ?>
</body>
</html>
Snippets of my index.html:
<header>
<!-- Uploader -->
<link href="dropzone.css" type="text/css" rel="stylesheet" />
<script src="dropzone.js"></script>
</header>
<body>
<div class="uploadingFiles">
<form action="parser.php" class="dropzone"></form>
<p><a href="view_upload.php">View Upload</a></p>
</div>
</body>
I've also noticed that when I click "View Upload" the entire script turns into a comment, I'm not sure if that has anything to do with it though.
<body>
<!--?php
$folder = "uploads";
if(is_dir($folder)){
$handler = opendir($folder);
$output = "";
while($files = readdir($handler)){
if(!is_dir($files)){
$output .= "<img src=\"uploads/{$files}\" width='180' height='180'-->";
}
}
}
echo $output;
</body>
</div>
Try changing this line: $destination_path = dirname(__FILE__).$dir_separator.$folder.$dir_separator;
to $destination_path = $folder.$dir_separator;
and see if that fixes the problem