php - Get file name after remote file grabbing -
i'm using php file grabber script. put url of remote file on field , file directly uploaded server. code looks this:
<?php ini_set("memory_limit","2000m"); ini_set('max_execution_time',"2500"); foreach ($_post['store'] $value){ if ($value!=""){ echo("attempting: ".$value."<br />"); system("cd files && wget ".$value); echo("<b>success: ".$value."</b><br />"); } } echo("finished file uploading."); ?>
after uploading file display direct url file : example
finished file uploading, direct url: http://site.com/files/grabbedfile.zip
could me how determine file name of last uploaded file within code?
thanks in advance
you can use wget log files. add -o logfilename
.
here small function get_filename( $wget_logfile )
ini_set("memory_limit","2000m"); ini_set('max_execution_time',"2500"); function get_filename( $wget_logfile ) { $log = explode("\n", file_get_contents( $wget_logfile )); foreach ( $log $line ) { preg_match ("/^.*saving to: .{1}(.*).{1}/", $line, $find); if ( count($find) ) return $find[1]; } return ""; } $tmplog = tempnam("/tmp", "wgetlog"); $filename = ""; foreach ($_post['store'] $value){ if ($value!=""){ echo("attempting: ".$value."<br />"); system("cd files && wget -o $tmplog ".$value); // -o logfile $filename = get_filename( $tmplog ); // current filename unlink ( $tmplog ); // remove logfile echo("<b>success: ".$value."</b><br />"); } } echo("finished file uploading."); echo "last file: ".$filename;
Comments
Post a Comment