问题
I'm using the jquery library blueimp upload. I want to upload images to a different directory. I just modified the /server/php/index.php 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 <
Safari ->SyntaxError: JSON Parse error: Unrecognized token '<'
The result of /server/php/index.php 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
回答1:
You must use quotes when you define a constant
define('DIR_DOWNLOAD', "/Applications/XAMPP/htdocs/villalba2");
Then the json output will be parsable
回答2:
In order to define constants they must be quoted in the definition -
define("DIR_DOWNLOAD", "/Applications/XAMPP/htdocs/villalba2");
define("HTTP_SERVER", "localhost/villalba2");
回答3:
change
//error_reporting(E_ALL | E_STRICT);
error_reporting(E_STRICT);
来源:https://stackoverflow.com/questions/26804480/blueimp-jquery-upload-syntaxerror-unexpected-token