【问题标题】:How to make Uploader in CGI shell script如何在 CGI shell 脚本中制作 Uploader
【发布时间】:2015-11-25 13:14:00
【问题描述】:

我想在 CGI bash(shell 脚本)中制作上传脚本

通过“浏览”和“提交”来上传文件

注意:上传者without ftp 和without ftp 或 cpanel 或 sftp 的用户和密码

或:

我想制作 CGI 脚本“bash”,以便脚本可以将文件上传到网络。

【问题讨论】:

  • 您需要提供更多信息。例如:-到目前为止,您尝试过什么?
  • :/我的问题很清楚 -- 我们如何编码上传器,上传器用于在网站上上传文件,我想在 CGI shell 脚本中编码上传器,怎么能 - -
  • 看看这个是否有帮助 - stackoverflow.com/questions/1894347/…
  • 没用,我想在 CGI 中制作,没有 ftp 或 sftp,也没有用户和密码,
  • 向上请需要帮助-_-

标签: bash shell cgi uploader


【解决方案1】:

我使用Uploading Binary Files in Bash CGI Script 中的示例进行了此操作,但我们稍后修复了一个小错误:

file=/tmp/$$-$RANDOM

# CGI output must start with at least empty line (or headers)
printf '\r\n'
  cat <<EOF
<html>
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
EOF

IFS=$'\r'
read -r delim_line

IFS=''
delim_line="${delim_line}--"$'\r'

read -r line
filename=$(echo $line | sed 's/^.*filename=//' | sed 's/\"//g' | sed 's/.$//')
fileext=${filename##*.}

while read -r line; do
    test "$line" = '' && break
    test "$line" = $'\r' && break
done

# Note: This will result in junk at end of line (see format above)
cat > $file

# Get the line count
LINES=$(wc -l $file | cut -d ' ' -f 1)

# Remove the last line
head -$((LINES - 1)) $file >$file.1

# Copy eveything but the last line to a temp file
head -$((LINES - 2)) $file.1 >$file.2

# Copy the new last line but remove trailing \r\n
tail -1 $file.1 > $file.3
tail -c 2 $file.3 > $file.5
CRLF=$(hexdump -ve '/1 "%.2x"' $file.5)
# Check if the last two bytes are \r\n
if [ "$CRLF" = "0d0a" ];then
   BYTES=$(wc -c $file.3 | cut -d ' ' -f 1)
   truncate -s $((BYTES-2)) $file.3
fi

rm $file.5
cat $file.2 $file.3 > $file.4
cp $file.4 $file

cat <<EOF
<h1>Upload Successful</h1>
EOF

cat <<EOF
</body>
</html>
EOF

exit 0

【讨论】:

  • parsley72 非常酷的解决方案,谢谢。我现在在我的网站上使用你的代码。您的解决方案是我在整个互联网上找到的唯一一个可用于上传二进制文件的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
  • 1970-01-01
  • 2019-08-11
  • 2014-01-24
  • 2010-10-28
  • 1970-01-01
相关资源
最近更新 更多