Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP脚本中重命名图像文件名?_Php_Image_Photo_Rename - Fatal编程技术网

在PHP脚本中重命名图像文件名?

在PHP脚本中重命名图像文件名?,php,image,photo,rename,Php,Image,Photo,Rename,这是一个基本的转载程序,我用它将一些图像从一台服务器转载到另一台服务器。这是一个基本的脚本,允许我输入一个URL,单击下载,它将保存到我服务器上的一个目录并显示新的URL 我需要添加一些东西,让我的图像随机数字文件名自动在同一时间。我今晚玩了一下,离它很近,但运气不好。您可以将该功能添加到工具中吗?我很忙,因为我需要在周一之前使用该工具进行一个项目,所以我决定寻求帮助来完成这项工作。提前感谢 <?php // Check if form has been submitted if($_P

这是一个基本的转载程序,我用它将一些图像从一台服务器转载到另一台服务器。这是一个基本的脚本,允许我输入一个URL,单击下载,它将保存到我服务器上的一个目录并显示新的URL

我需要添加一些东西,让我的图像随机数字文件名自动在同一时间。我今晚玩了一下,离它很近,但运气不好。您可以将该功能添加到工具中吗?我很忙,因为我需要在周一之前使用该工具进行一个项目,所以我决定寻求帮助来完成这项工作。提前感谢

<?php

// Check if form has been submitted
if($_POST['submit']){

    ini_set("max_execution_time", 0);   // no time-outs!
    ignore_user_abort(true);            // Continue downloading even after user closes the browser.


    // URLS -- One on each line
    $URL = $_POST['url'];

    // Relative path to Save downloaded images
    // Default is "downloads"
    // Make sure that it is writable (chmoded correctly)
    $folder = $_POST['folder']; 

    // Check if User has provided a local folder
    if (!$folder || !isset($folder)){

        // Generate error if left blank by user.
        die ("Please specify local folder name");
    }

    // Split all URLS into an array
    $urls = split("\n", $URL);

    // Remove Carriage Returns (useful for Windows-based browsers)
    $urls = str_replace("\r", "", $urls);

$mh = curl_multi_init();
foreach ($urls as $i => $url) {
    $path = pathinfo($url);
    $g=$folder . "/" . $path["basename"] ;
        // Check if file already exists on local folder.
    if(file_exists($g)){

        // If exists, delete the file so it always contains the latest update.  
        unlink($g) or die("Unable to delete existing '$g'!");
    }
    // Update the user of what's going on
    echo "$i) <b>Sucess! Your image has been transloaded from:</b> <br><small><small>$url</small></small><p><b>Your new image URL is:</b><br>http://myURL.com/gallery/$g<br />";

    if(!is_file($g)){
        $conn[$i]=curl_init($url);
        $fp[$i]=fopen ($g, "w");
        curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
        curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
 //       curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,1000);
        curl_multi_add_handle ($mh,$conn[$i]);
    }
}
do {
    $n=curl_multi_exec($mh,$active);
}
while ($active);
foreach ($urls as $i => $url) {
    curl_multi_remove_handle($mh,$conn[$i]);
    curl_close($conn[$i]);
    fclose ($fp[$i]);
}
curl_multi_close($mh);

} //  task closed
?>
<br />
<br />
<fieldset>
        <legend>
            <label for="url">Download Remote Files And Save Locally</label>
        </legend>
        <form method=POST>
            <label for="url">URL: </label><br />
            <textarea rows=15 cols=75 id="url" name="url"><?= $URL ?></textarea><br />
            <label for="folder">Local folder : </label><input type=text id="folder" name="folder" value="downloads"/>
            <input type=submit name="submit" value="Download Files!" />
        </form>
</fieldset>

已解决。解决方案是添加$g=$文件夹。"/" . 兰特(1000099999)。“.jpg”;