[Help] $ bodyereg_replace ($ value, $ fileurl, $ body) php variable ereg_replace
Function remoteimg ($ imgurl) {import ('@. ORG. session '); // A Session $ mid = Session: get ('mid') is not included in the file header '); // Obtain the mid // file storage directory path $ imgPath = "/Uploads/$ mid ". date ('ymmd '). '/files/'; // The current date folder url dir_create ($ imgPath); // create this directory // File Save Directory URL $ imgUrl =. '/'. $ imgPath; // get the root parameter value configured in the current file set_time_limit (0); // code execution time limit, it is 0, and the execution of the program is unknown. $ milliSecond = date ("dHis "). '_'; // record the current date and time score in seconds if (! Is_dir ($ imgPath) @ mkdir ($ imgPath, 0777); // if the directory does not exist, create a directory (full permission) $ value = trim ($ imgurl ); // Remove the space at both ends of the image address $ get_file = @ file_get_contents ($ value); // Obtain the image data $ rndFileName = $ imgPath. $ milliSecond. $ key. '. '. substr ($ value,-3, 3); // Generate the file path ???? $ Key ???? $ Fileurl = $ imgUrl. $ milliSecond. $ key. '. '. substr ($ value,-3, 3); // Generate the file path if ($ get_file) in the root path) {// If you have obtained the file $ fp = @ fopen ($ rndFileName, 'w'); // create a path and file @ fwrite ($ fp, $ get_file ); // write image data @ fclose ($ fp); // Close the write data stream $ body = ereg_replace ($ value, $ fileurl, $ body ); // check whether the $ body contains a string that matches the value. If yes, replace the string with fileurl.} echo $ body ;}
Who can explain the functions of this method?
What does $ body mean?
Reply to discussion (solution)
$ Body only causes program errors!
$ Body only causes program errors! The PHP official website said that an error will be reported when uninitialized variables are used. But what is the function of this method? I added all the comments, but did not understand what he was trying to do...
If it weren't for you to paste the full code
Otherwise, it is not a normal practice to directly echo $ body in the function as the debugging code left by the author.
The function is used to download images and save them to a local website.
Body guesses that the source code of other websites is downloaded, and the source image address is replaced with the address of this site.
However, the program here is problematic and should be like
If it weren't for you to paste the full code
Otherwise, it is not a normal practice to directly echo $ body in the function as the debugging code left by the author.
It seems like it was written together.
$ Body = get content ..... remoteimg content is omitted if ($ get_file) {// if the file has been obtained $ fp = @ fopen ($ rndFileName, 'w '); // create a path and file @ fwrite ($ fp, $ get_file); // write image data @ fclose ($ fp ); // Close the written data stream $ body = ereg_replace ($ value, $ fileurl, $ body); // check whether the $ body contains a string that matches the value, if yes, use fileurl to replace} echo $ body;
But when it was encapsulated, it was just a brain.