Sample code for saving web images collected by PHP to a local device
- /**
- * Save the webpage file to a local device (used to collect images)
- * Edit: bbs.it-home.org
- * @ Param file path $ sUrl
- * @ Param save the local path $ sSavePath
- * @ Return boolean
- */
- Function download_file ($ sUrl, $ sSavePath = '')
- {
- $ SFileName = GetUrlFileExt ($ sUrl );
- $ C = file_get_contents ($ sUrl );
- Return file_put_contents ($ sSavePath. '/'. $ sFileName, $ c );
- }
-
- /**
- * Get the file name
- *
- * @ Param webpage URL $ sUrl
- * @ Return string
- */
- Function GetUrlFileExt ($ sUrl)
- {
- $ AAry = parse_url ($ sUrl );
- $ SFile = basename ($ aAry ['path']);
- $ SExt = explode ('.', $ sFile );
- Return $ sExt [0]. '.'. $ sExt [1];
- }
-
- $ SPath = "D:/marker_imgs ";
- For ($ I = 1; I I <100; $ I ++)
- {
- $ SUrl = "http://bbs.it-home.org/red/marker$ I .png ";
- Download_file ($ sUrl, $ sPath );
- }
- ?>
|