Add watermark code modification to the fck Upload image. To add the watermark code to the fck Upload image, find the editorfilemangerconectorsphpcommands. php file and replace the following php code with your commands. php file. F fck uploads an image and adds watermark code modification. // you only need to find the editor/filemanger/conectors/php/commands. php file and replace the following php code with your commands. php file.
Add watermark code modification for fck Image uploading
// You only need to find the editor/filemanger/conectors/php Tutorial/commands. php Tutorial file and replace the following php code with your commands. php file.
Function getfolders ($ resourcetype, $ currentfolder)
{
// Map the virtual path to the local server path.
$ Sserverdir = servermapfolder ($ resourcetype, $ currentfolder, 'getfolders ');
// Array that will hold the folders names.
$ Afolders = array ();
$ Ocurrentfolder = opendir ($ sserverdir );
While ($ sfile = readdir ($ ocurrentfolder ))
{
If ($ sfile! = '.' & $ Sfile! = '..' & Is_dir ($ sserverdir. $ sfile ))
$ Afolders [] =' ';
}
Closedir ($ ocurrentfolder );
// Open the "folders" node.
Echo" ";
Natcasesort ($ afolders );
Foreach ($ afolders as $ sfolder)
Echo $ sfolder;
// Close the "folders" node.
Echo"";
}
Function getfoldersandfiles ($ resourcetype, $ currentfolder)
{
// Map the virtual path to the local server path.
$ Sserverdir = servermapfolder ($ resourcetype, $ currentfolder, 'getfoldersandfiles ');
// Arrays that will hold the folders and files names.
$ Afolders = array ();
$ Afiles = array ();
$ Ocurrentfolder = opendir ($ sserverdir );
While ($ sfile = readdir ($ ocurrentfolder ))
{
If ($ sfile! = '.' & $ Sfile! = '..')
{
If (is_dir ($ sserverdir. $ sfile ))
$ Afolders [] =' ';
Else
{
$ Ifilesize = @ filesize ($ sserverdir. $ sfile );
If (! $ Ifilesize ){
$ Ifilesize = 0;
}
If ($ ifilesize> 0)
{
$ Ifilesize = round ($ ifilesize/1024 );
If ($ ifilesize <1) $ ifilesize = 1;
}
$ Afiles [] =' ';
}
}
}
// Send the folders
Natcasesort ($ afolders );
Echo' ';
Foreach ($ afolders as $ sfolder)
Echo $ sfolder;
Echo'';
// Send the files
Natcasesort ($ afiles );
Echo' ';
Foreach ($ afiles as $ sfiles)
Echo $ sfiles;
Echo'';
}
Function createfolder ($ resourcetype, $ currentfolder)
{
If (! Isset ($ _ get )){
Global $ _ get;
}
$ Serrornumber = '0 ';
$ Serrormsg = '';
If (isset ($ _ get ['newfoldername'])
{
$ Snewfoldername = $ _ get ['newfoldername'];
$ Snewfoldername = sanitizefoldername ($ snewfoldername );
If (strpos ($ snewfoldername ,'..')! = False)
$ Serrornumber = '000000'; // invalid folder name.
Else
{
// Map the virtual path to the local server path of the current folder.
$ Sserverdir = servermapfolder ($ resourcetype, $ currentfolder, 'createfolder ');
If (is_writable ($ sserverdir ))
{
$ Sserverdir. = $ snewfoldername;
$ Serrormsg = createserverfolder ($ sserverdir );
Switch ($ serrormsg)
{
Case '':
$ Serrornumber = '0 ';
Break;
Case 'invalidargument ':
Case 'no such file or directory ':
$ Serrornumber = '000000'; // path too long.
Break;
Default:
$ Serrornumber = '123 ';
Break;
}
}
Else
$ Serrornumber = '123 ';
}
}
Else
$ Serrornumber = '123 ';
// Create the "error" node.
Echo' ';
}
Function fileupload ($ resourcetype, $ currentfolder, $ scommand)
{
If (! Isset ($ _ files )){
Global $ _ files;
}
$ Serrornumber = '0 ';
$ Sfilename = '';
If (isset ($ _ files ['newfile']) &! Is_null ($ _ files ['newfile'] ['tmp _ name'])
{
Global $ config;
$ Ofile = $ _ files ['newfile'];
// Map the virtual path to the local server path.
$ Sserverdir = servermapfolder ($ resourcetype, $ currentfolder, $ scommand );
// Get the uploaded file name.
$ Sfilename = $ ofile ['name'];
$ Sfilename = sanitizefilename ($ sfilename );
$ Soriginalfilename = $ sfilename;
// Get the extension.
$ Sextension = substr ($ sfilename, (strrpos ($ sfilename, '.') + 1 ));
$ Sextension = strtolower ($ sextension );
If (isset ($ config ['secureimageupload'])
{
If ($ isimagevalid = isimagevalid ($ ofile ['tmp _ name'], $ sextension) === false)
{
$ Serrornumber = '123 ';
}
}
If (isset ($ config ['htmlextension'])
{
If (! Ishtmlextension ($ sextension, $ config ['htmlextension']) &
($ Detecthtml = detecthtml ($ ofile ['tmp _ name']) = true)
{
$ Serrornumber = '123 ';
}
}
// Check if it is an allowed extension.
If (! $ Serrornumber & isallowedext ($ sextension, $ resourcetype ))
{
$ Icounter = 0;
While (true)
{
$ Sfilepath = $ sserverdir. $ sfilename;
// $ Sfilepath = $ sserverdir. time (). $ sextension;
If (is_file ($ sfilepath ))
{
$ Icounter ++;
$ Sfilename = removeextension ($ soriginalfilename). '('. $ icounter. ').'. $ sextension;
$ Serrornumber = '123 ';
}
Else
{
Move_uploaded_file ($ ofile ['tmp _ name'], $ sfilepath );
If (is_file ($ sfilepath ))
{
If (isset ($ config ['chmodonupload']) &! $ Config ['chdonupload'])
{
Break;
}
$ Permissions = 0777;
If (isset ($ config ['chmodonupload']) & $ config ['chmodonupload'])
{
$ Permissions = $ config ['chmodonupload'];
}
$ Oldumask = umask (0 );
Chmod ($ sfilepath, $ permissions );
Umask ($ oldumask );
}
Break;
}
}
// Add a watermark
// Add start
$ Waterimg = "php100.com.png"; // modify the address of your watermark image.
If ($ watermark = 1)
{
$ Image_size = getimagesize ($ sfilepath );
$ Iinfo = getimagesize ($ sfilepath, $ iinfo );
$ Nimage = imagecreatetruecolor ($ image_size [0], $ image_size [1]);
$ White = imagecolorallocate ($ nimage, 255,255,255 );
$ Black = imagecolorallocate ($ nimage, 0, 0 );
$ Red = imagecolorallocate ($ nimage, 255, 0, 0 );
Imagefill ($ nimage, 0, 0, $ white );
Switch ($ iinfo [2])
{
Case 1:
$ Simage = imagecreatefromgif ($ sfilepath );
Break;
Case 2:
$ Simage = imagecreatefromjpeg ($ sfilepath );
Break;
Case 3:
$ Simage = imagecreatefrompng ($ sfilepath );
Break;
// Case 6:
// $ Simage = imagecreatefromwbmp ($ sfilepath );
// Break;
Default:
Die ("unsupported file types ");
Exit;
}
Imagecopy ($ nimage, $ simage, 0, 0, 0, $ image_size [0], $ image_size [1]);
Switch ($ watertype)
{
Case 1: // add a watermark string
Imagestring ($ nimage, 2, 3, $ image_size [1]-15, $ waterstring, $ black );
Break;
Case 2: // add a watermark image
$ Simage1 = imagecreatefrompng ($ waterimg );
Imagecopy ($ nimage, $ simage1, $ image_size [0]/2, $ image_size [0]/0,240, 65 );
Imagedestroy ($ simage1 );
Break;
}
Switch ($ iinfo [2])
{
Case 1:
Imagegif ($ nimage, $ sfilepath );
// Imagejpeg ($ nimage, $ sfilepath );
Break;
Case 2:
Imagejpeg ($ nimage, $ sfilepath );
Break;
Case 3:
Imagepng ($ nimage, $ sfilepath );
Break;
// Case 6:
// Imagewbmp ($ nimage, $ sfilepath );
/// Imagejpeg ($ nimage, $ sfilepath );
// Break;
}
// Overwrite the original uploaded File
Imagedestroy ($ nimage );
Imagedestroy ($ simage );
}
// Add watermark results
If (file_exists ($ sfilepath ))
{
// Previous checks failed, try once again
If (isset ($ isimagevalid) & $ isimagevalid ===- 1 & isimagevalid ($ sfilepath, $ sextension) === false)
{
@ Unlink ($ sfilepath );
$ Serrornumber = '123 ';
}
Else if (isset ($ detecthtml) & $ detecthtml ===- 1 & detecthtml ($ sfilepath) === true)
{
@ Unlink ($ sfilepath );
$ Serrornumber = '123 ';
}
}
}
Else
$ Serrornumber = '123 ';
}
Else
$ Serrornumber = '123 ';
$ Sfileurl = combinepaths (getresourcetypepath ($ resourcetype, $ scommand), $ currentfolder );
$ Sfileurl = combinepaths ($ sfileurl, $ sfilename );
Senduploadresults ($ serrornumber, $ sfileurl, $ sfilename );
Exit;
}?>
Http://www.bkjia.com/PHPjc/444909.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444909.htmlTechArticlefck Upload image add watermark code modification // we just need to find the editor/filemanger/conectors/php/commands. php file to replace the following php code with your commands. php file on the line. F...