Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

php - 如何在php的上传表单上隐藏我的api密钥(how to hide my api key on an upload form on php)

   <form enctype="multipart/form-data" action="https://SERVER.com/upload/02" method="post">
    <input type="hidden" name="api_key" value="API-KEY-HERE">
    <input name="file" type="file">
    <input type="submit">
   </form>

Is it possible to recover the file and send it to the server with another php page?

(是否有可能恢复文件并将其发送到带有另一个php页面的服务器?)
The API key should not appear!

(API密钥不应出现!)
My goal is that the key does not appear anywhere!

(我的目标是密钥不会出现在任何地方!)

  ask by kod Oklm translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try to send the file to your server, then your server will make a POST request which includes both API key and the file to the target server.

(您可以尝试将文件发送到服务器,然后服务器将向POST请求发出请求,其中包括API密钥和文件到目标服务器。)

If you are using jquery:

(如果您使用的是jquery:)

var formData = new FormData();
formData.append('file', $('[type=file]')[0].files[0]);

$.ajax({
    type: 'POST',
    url: '/your-current-server',
    data: formData,
    processData: false,
    contentType: false
}).done(() => console.log('upload completed'))
  .fail(e => console.log('upload failed:', e));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...