简体   繁体   English

Windows批处理文件以调用PHP脚本

[英]Windows Batch File to call PHP Script

Can somebody please explain what is this batch file trying to do 有人可以解释一下该批处理文件试图做什么

setlocal
SET tmpfile="temp3.txt"

for %%f in (FY2?_20??.JPG) do (
    curl --form image=@%%f http://www.test.com/images/image_upload.php>%tmpfile%

    REN "%%f" "DONE-%%f"
    REN %tmpfile% "%%f.log"
 )

thank you for your any help and suggestions 感谢您的帮助和建议

All it does is upload a bunch of images that match a certain filename mask to a remote server and stores the curl output in a log file, then renames those images when they've been processed. 它所做的就是将一堆与某个文件名掩码匹配的图像上传到远程服务器,并将curl输出存储在日志文件中,然后在处理完这些图像后重命名它们。

But since that answer is short and boring, I'll go through the script line by line. 但是,由于该答案简短而无聊,因此我将逐行介绍脚本。


setlocal

Sandboxes the variables that get set in the script so that they can't be accessed once the script ends. 沙盒化在脚本中设置的变量,以便脚本结束后就无法访问它们。 Not necessary, but good practice. 没有必要,但是好的做法。

SET tmpfile="temp3.txt"

Sets a variable called tmpfile to the value temp3.txt . 将名为tmpfile的变量设置为temp3.txt

for %%f in (FY2?_20??.JPG) do (

Iterates over the list of every JPG file in the current directory that starts with FY2 , then some character, then _20 , then two more characters. 迭代与开始在当前目录中所有JPG文件的列表FY2 ,然后一些字符,然后_20 ,然后两个字符。

    curl --form image=@%%f http://www.test.com/images/image_upload.php>%tmpfile%

Uploads each image to www.test.com via that site's image_upload.php page. 通过该站点的image_upload.php页面将每个图像上传到www.test.com。 The output of the curl command gets redirected to the file whose location got stored in the %tmpfile% variable earlier. curl命令的输出将重定向到文件的位置,该文​​件的位置之前已存储在%tmpfile%变量中。 > says to overwrite the contents of the file or create a new file if one does not exist. >表示要覆盖文件内容或如果不存在则创建一个新文件。 The --form option makes curl send the image via POST rather than GET. --form选项使curl通过POST而不是GET发送图像。

    REN "%%f" "DONE-%%f"

Appends the string "DONE-" in front of the current file name 在当前文件名前面附加字符串“ DONE-”

    REN %tmpfile% "%%f.log"

Changes the name of the log file to match the name of the file that was just uploaded. 更改日志文件的名称,使其与刚刚上传的文件的名称匹配。 This line tells me that the %tmpfile% variable is redundant and the curl output could simply have been redirected to %%f.log without needing a temporary file. 这行告诉我%tmpfile%变量是多余的,并且curl输出可以直接重定向到%%f.log而不需要临时文件。

 )

This just closes the for loop. 这只会关闭for循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM