photo

As it was previously pointed out, this the correct way:

relative_urls : false,
remove_script_host : false,
convert_urls : true,

HOWEVER, there is one thing to mention that will make you wonder why it's not working even though you have specified the proper text above. Ensure the false and true do NOT have quotes around them.

 

Tiny Mce Image Upload with Full URL

Full TinyMCE Code :

<script>
tinymce.init({
	selector: '#mytextarea',
	height: 400,
	theme: 'modern',
	plugins: [
	'advlist autolink lists link image charmap print preview hr anchor pagebreak',
	'searchreplace wordcount visualblocks visualchars code fullscreen',
	'insertdatetime media nonbreaking save table contextmenu directionality',
	'emoticons template paste textcolor colorpicker textpattern imagetools codesample '
	],
	toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
	toolbar2: 'print preview media | forecolor backcolor | emoticons | codesample ',
	images_upload_url: 'upload.php',
	image_advtab: false,
	relative_urls : false,
	remove_script_host : false,
	convert_urls : true,
	images_upload_handler: function (blobInfo, success, failure) {
		var xhr, formData;
      
		xhr = new XMLHttpRequest();
		xhr.withCredentials = false;
		xhr.open('POST', 'upload.php');
      
		xhr.onload = function() {
			var json;
        
			if (xhr.status != 200) {
				failure('HTTP Error: ' + xhr.status);
				return;
			}
        
			json = JSON.parse(xhr.responseText);
        
			if (!json || typeof json.location != 'string') {
				failure('Invalid JSON: ' + xhr.responseText);
				return;
			}
        
			success(json.location);
		};
      
		formData = new FormData();
		formData.append('file', blobInfo.blob(), blobInfo.filename());
      
		xhr.send(formData);
	},
	codesample_languages: [
	{text: 'HTML/XML', value: 'markup line-numbers'},
	{text: 'JavaScript', value: 'javascript'},
	{text: 'CSS', value: 'css'},
	{text: 'PHP', value: 'php line-numbers'},
	{text: 'Ruby', value: 'ruby'},
	{text: 'Python', value: 'python'},
	{text: 'Java', value: 'java'},
	{text: 'C', value: 'c'},
	{text: 'C#', value: 'csharp'},
	{text: 'C++', value: 'cpp'}
	],
	content_css: [
	'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',

	]
});
</script>

 

Upload File Code :

upload.php

 

<?php
// Allowed origins to upload images
$accepted_origins = array("http://localhost","https://www.tutorialswave.com");

// Images upload path
$imageFolder = "../../uploadimages/";

reset($_FILES);
$temp = current($_FILES);
if(is_uploaded_file($temp['tmp_name'])){
	if(isset($_SERVER['HTTP_ORIGIN'])){
		// Same-origin requests won't set an origin. If the origin is set, it must be valid.
		if(in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)){
			header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
		}else{
			header("HTTP/1.1 403 Origin Denied");
			return;
		}
	}
  
	// Sanitize input
	if(preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])){
		header("HTTP/1.1 400 Invalid file name.");
		return;
	}
  
	// Verify extension
	if(!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))){
		header("HTTP/1.1 400 Invalid extension.");
		return;
	}
  
	// Accept upload if there was no origin, or if it is an accepted origin
	$filetowrite = $imageFolder . $temp['name'];
	move_uploaded_file($temp['tmp_name'], $filetowrite);
  
	// Respond to the successful upload with JSON.
	echo json_encode(array('location' => $filetowrite));
} else {
	// Notify editor that the upload failed
	header("HTTP/1.1 500 Server Error");
}
?>

 

Advertisement