File_get_contents: move the file to the server & nbsp; use the ckeditor editor to copy the image in the word file and check that the source code of the image address is file: in this form, I wrote a method to register an event during pasting, use a regular expression to match similar image addresses, and then asynchronously upload it to the php script file for processing. the processing logic is, use file_get _ file_get_contents to move a file similar to file: // to the server.
Use the ckeditor editor to copy the image in the word file and check that the source code of the image address is in the format of file: //. then I wrote a method to register an event during pasting, use a regular expression to match similar image addresses, and then asynchronously upload them to the php script file for processing. the processing logic is: read the image address using file_get_contents, and then write it to the specified directory using file_put_contents. because it is tested locally, no problem. Svn went to the server. after testing, we found that the image size was 0 KB. later, we used is_file for testing and printed false. The local size was true. Is it true that file_get_contents could not read the local image on the server.
// Save the image pasted from the word document to a local directory, and then change its address to return
Public function tranPic (){
// Detection
$ _ POST = unflip ($ _ POST );
$ Content = strval ($ _ POST ['HTML ']);
If (! $ Content ){
Echo '';
Exit;
}
// Domain name for storing images
$ ImgPath = C ('tmpl _ PARSE_STRING ');
// The path after the image is saved
$ Pre = '../Uploads /';
$ Pic = 'ueditor/'. date ('ymd', time ()).'/';
Mk_dir ($ pre. $ pic );
// Extract the image using regular expressions
$ Pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? :[\. Gif | \. jpeg | \. jpg | \. bmp | \. bnp Paribas | \. png | \. GIF | \. JPG | \. BMP | \. BNP Paribas | \. PNG | \. JPEG]) [\ '| \ "]. *? [\/]?> /";
Preg_match_all ($ pattern, $ content, $ match );
// Replace the image address with the address in this project.
Foreach ($ match as $ key =>&$ value ){
If ($ key> 0 ){
Continue;
}
Foreach ($ value as $ k => $ v ){
// Obtain the image suffix. the first five characters of the main image are file:
If (substr ($ match [1] [$ k], 0, 5) = 'File :'){
$ Ext = pathinfo ($ match [1] [$ k], PATHINFO_EXTENSION );
$ Data = file_get_contents ($ match [1] [$ k]);
$ Filename = uniqid (). '.'. $ ext;
File_put_contents ($ pre. $ pic. $ filename, $ data );
$ Content = str_replace ($ v, str_replace ($ match [1] [$ k], $ imgPath ['.. /Uploads/']. $ pic. $ filename, $ v), $ content );
}
}
}
Echo $ content;
}
------ Solution --------------------
Yes, file_get_contents cannot read the local image on the server.
However, you can consider transferring data through a local server.