69764

blueimp jquery upload SyntaxError: Unexpected token <

Question:

I'm using the jquery library blueimp upload. I want to upload images to a different directory. I just modified the /server/php/<strong>index.php</strong> file (only this file) :

error_reporting(E_ALL | E_STRICT); require_once('UploadHandler.php'); //$upload_handler = new UploadHandler(); define(DIR_DOWNLOAD, "/Applications/XAMPP/htdocs/villalba2"); define(HTTP_SERVER, "localhost/villalba2"); $blogId= "Mobiliario"; $upload_handler = new UploadHandler(array( 'upload_dir' => DIR_DOWNLOAD . '/uploads/' . $blogId. '/', 'upload_url' => HTTP_SERVER . '/uploads/' . $blogId. '/', ));

the permission folder are 777

The images are loaded correctly in the directory that i want, but I get this error:

Chrome ->SyntaxError: Unexpected token < <br /> Safari ->SyntaxError: JSON Parse error: Unrecognized token '<'

The result of /server/php/<strong>index.php</strong> is:

<b>Notice</b>: Use of undefined constant DIR_DOWNLOAD - assumed 'DIR_DOWNLOAD' in <b>/Applications/XAMPP/xamppfiles/htdocs/villalba2/up/server/php/index.php</b> on line <b>16</b><br /> <br /> <b>Notice</b>: Use of undefined constant HTTP_SERVER - assumed 'HTTP_SERVER' in <b>/Applications/XAMPP/xamppfiles/htdocs/villalba2/up/server/php/index.php</b> on line <b>17</b><br /> {"files":[{"name":"cama (1).jpg","size":101775,"url":"localhost\/villalba2\/uploads\/Mobiliario\/cama%20%281%29.jpg","thumbnailUrl":"localhost\/villalba2\/uploads\/Mobiliario\/thumbnail\/cama%20%281%29.jpg","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=cama%20%281%29.jpg","deleteType":"DELETE"},{"name":"cama (2).jpg","size":101775,"url":"localhost\/villalba2\/uploads\/Mobiliario\/cama%20%282%29.jpg","thumbnailUrl":"localhost\/villalba2\/uploads\/Mobiliario\/thumbnail\/cama%20%282%29.jpg","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=cama%20%282%29.jpg","deleteType":"DELETE"},{"name":"cama (3).jpg","size":101775,"url":"localhost\/villalba2\/uploads\/Mobiliario\/cama%20%283%29.jpg","thumbnailUrl":"localhost\/villalba2\/uploads\/Mobiliario\/thumbnail\/cama%20%283%29.jpg","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=cama%20%283%29.jpg","deleteType":"DELETE"},{"name":"cama.jpg","size":101775,"url":"localhost\/villalba2\/uploads\/Mobiliario\/cama.jpg","thumbnailUrl":"localhost\/villalba2\/uploads\/Mobiliario\/thumbnail\/cama.jpg","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=cama.jpg","deleteType":"DELETE"},{"name":"mantelera.jpg","size":50986,"url":"localhost\/villalba2\/uploads\/Mobiliario\/mantelera.jpg","thumbnailUrl":"localhost\/villalba2\/uploads\/Mobiliario\/thumbnail\/mantelera.jpg","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=mantelera.jpg","deleteType":"DELETE"},{"name":"test (1).png","size":15,"url":"localhost\/villalba2\/uploads\/Mobiliario\/test%20%281%29.png","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=test%20%281%29.png","deleteType":"DELETE"},{"name":"test (2).png","size":15,"url":"localhost\/villalba2\/uploads\/Mobiliario\/test%20%282%29.png","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=test%20%282%29.png","deleteType":"DELETE"},{"name":"test.png","size":15,"url":"localhost\/villalba2\/uploads\/Mobiliario\/test.png","deleteUrl":"http:\/\/localhost\/villalba2\/up\/server\/php\/?file=test.png","deleteType":"DELETE"}]}

Why dosen't work?? the images are upload in the correct folder :S

Thanks!

---THIS LAST PART IS SOLVED-----

Edit:

Now the the thumbs are not displayed on the browser..

Failed to load resource: the server responded with a status of 404 (Not Found) /localhost/villalba2/up/localhost/villalba2/uploads/Mobiliario/thumbnail/mbiliario.jpg

the correct absolute path it will be:

/localhost/villalba2/uploads/Mobiliario/thumbnail/mbiliario.jpg

the path: /localhost/villalba2/up/ is where is the blueimp jquery upload core

Answer1:

You must use quotes when you define a constant

define('DIR_DOWNLOAD', "/Applications/XAMPP/htdocs/villalba2");

Then the json output will be parsable

Answer2:

In order to <a href="http://php.net/manual/en/language.constants.php" rel="nofollow">define constants</a> they must be quoted in the definition -

define("DIR_DOWNLOAD", "/Applications/XAMPP/htdocs/villalba2"); define("HTTP_SERVER", "localhost/villalba2");

Answer3:

change

//error_reporting(E_ALL | E_STRICT); error_reporting(E_STRICT);

Recommend

  • blueimp jquery upload SyntaxError: Unexpected token <
  • Swift: self.init (coder : aDecoder) is crashing app with EXC_BAD_ACCESS
  • HTAccess mod rewrite issue using QSA
  • SQLAlchemy equivalent of Django ORM's relationship-spanning filter
  • Sending formData with Uploadify not working with Large file size
  • Routing based on same parameter(s) pattern and different pages in web forms
  • How to upload a file using the BlobStore in Python App Engine?
  • Promisify functions with callbacks in typescript
  • How run two Chrome driver for one profile with Selenium Webdriver Nodejs?
  • Generating C# documentation without building an Xml document [closed]
  • Retrieve IP address of device
  • Multicolored edittext hint
  • cygwin cannot exec 'git-add--interactive' permission denied
  • Redux Form - Not able to type anything in input
  • How can I sort a a table with VBA with given text condition?
  • How to set ini file attributes during an Inno install
  • Ajax Loaded meta Tags
  • Paperclip, set path outside of rails root folder
  • All Classes Conforming to Protocol Inherit Default Implementation
  • Rearranging Cells in UITableView Bug & Saving Changes
  • File upload with ng-file-upload throwing error
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper folder structure for lots of source files
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • Angular 2 constructor injection vs direct access
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Java static initializers and reflection
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Linking SubReports Without LinkChild/LinkMaster
  • Append folder name and increment by 1 using batch script
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass