Dropzone.js not uploading the file


#1

Hi all,

client side :

<form action="upload_pkg_photo.php" class="dropzone"></form>

server side :slight_smile:

<?php

error_reporting(E_ALL);
error_reporting(-1); 
ini_set('display_errors', 'true');
include ($_SERVER["DOCUMENT_ROOT"] . "/config.php");


$ds = DIRECTORY_SEPARATOR;  //1
$storeFolder = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . "/uploads";   //2

if (!empty($_FILES)) {
     
    $tempFile = $_FILES['file']['tmp_name'];//3             
      
    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4
    $targetPath =  . $ds. $storeFolder . $ds;  //4
     
     
    $targetFile =  $targetPath. $_FILES['file']['name'];  //5
 
    move_uploaded_file($tempFile,$targetFile); //6 
}
?>     

The uploader shows success with it’s right mark. but upload folder in my case
domain.com/demo3/uploads is empty only. i make sure it is not uplaoded outside of this by doing a search in cpanel file manager for server wide. uploaded images are not found anyware.

whats wrongs people?


#2

Client side, you have a link to dropzone.js?


#3

Yh the file is linked along it’s css. form works perfectly.
i got it from github, did not do any modification to it. just downlod, uploaded to file manager and linked.
ill try to get u the file link in git in a moment.

The files dropzone.js and dropzone.css are from here


#4

The pages on GitHub don’t seem to have a lot of information on how to use it. The readme say the official repository is now at GitLab. There seems to be more information there.


#5

strange, i adjusted the code. but no luck, demo3/uplods folder is empty,

							  <div class="row">
								<div class="col-lg-12">
									<form action="/demo3/uploads" class="dropzone">
									  <div class="fallback">
										<input name="file" type="file" multiple />
									  </div>
									</form>	  				  
								</div>	 		
							  </div>

#6

I’ve never tried this, is the leading . a typo and does it make any difference?

$targetPath =  . $ds. $storeFolder . $ds;  //4

Do you intentionally assign $targetPath on a line, then write over it on the next line?


#7

it looks like site point code editor has remove certen part. actually the very basic dropzone.js tutorial is found here i just followed it. infact the tutorial is recommended in the official site. i have the correct syntax exactly as in tuto. yet no file is beig uploaded.

https://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php


#8

I’m still not sure what your upload folder should be, and whether it’s correct. Yours is very different to the one in the tutorial article.


#9

let me try with tutorial default :slight_smile:


#10

100% like in the tuto. no success :frowning:

<?php
$ds = DIRECTORY_SEPARATOR;  //1
 
$storeFolder = 'uploads';   //2
 
if (!empty($_FILES)) {
     
    $tempFile = $_FILES['file']['tmp_name'];          //3             
      
    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4
     
    $targetFile =  $targetPath. $_FILES['file']['name'];  //5
 
    move_uploaded_file($tempFile,$targetFile); //6
     
}
?>       


#11

Hi @afridy. and where is the client side? Something like:

Dropzone.options.yourForm = {
//Dropzone options
};

You need have a look on the project page


#12

ill try with dropzone options. i am googling… Thanks.


#13

Hi folks ,
i have come up with succes. Thanks all for the efforts. frankly i had to recall my php file upload lessons. then i undestand dropzone.js has nothing to do with server side and it only give a handle to file input. with all this lessons i was able to success fully upload the images now. it also the error log in the script path was also help full in finding erros like unable to move, file not exists etc errors. here is my final code for successfull dropzone upload.

form

<form action="upload_pkg_photo.php" class="dropzone"></form>
  • be sure to inclde dropzone.css and dropzone.js file in the header

server side php

<?php
if (!empty($_FILES)) {
  $errors= array();
  $file_name = $_FILES['file']['name'];
  $file_size =$_FILES['file']['size'];
  $file_tmp =$_FILES['file']['tmp_name'];
  $file_type=$_FILES['file']['type'];
 
  $explode = explode(".", $_FILES["file"]["name"]);
  $file_ext = end($explode);
  
  $expensions= array("jpeg","jpg","png");
  
  if(in_array($file_ext,$expensions)=== false){
	 $errors[]="extension not allowed, please choose a JPEG or PNG file.";
  }
  
  if($file_size > 2097152){
	 $errors[]='File size must be excately 2 MB';
  }
  
  if(empty($errors)==true){
	 move_uploaded_file($file_tmp,$_SERVER['DOCUMENT_ROOT'] . "/demo3/uploads/".$file_name);
	 echo "Success";
  }else{
	 print_r($errors);
  }
}
?>

Thank you all!


closed #14

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.