duanjieyi6582 2018-08-09 23:47
浏览 159
已采纳

将文件从本地文件系统复制并处理到另一台服务器的db

Preface: I have images being generated every few hours from a script. These images get saved to the local filesystem of a pi. My goal is to have a webpage display the latest image. I don't want the webserver running on the pi.

What I've tried: I created a php upload handler from an HTML form. This takes an image from the form, and places it on the webserver filesystem and inserts an ID, filename, date, and path into a database. My idea was to post each image using curl from the pi to the webserver and have it upload and inserted into the DB, and then deleted from the Pi's filesystem right after. For whatever reason I can't get the curl to post to the HTML form.

I know this is pretty jank. I don't want to scp the images to the webserver and have a cron job running every minute to process any new files because I want it to be real time, and also don't want php processes just hanging out every minute.

Any ideas would be greatly appreciated!

  • 写回答

2条回答 默认 最新

  • duanji1056 2018-08-10 01:30
    关注

    Thanks for everyone who looked!

    I figured this out using curl - something was wrong in my upload.php Here's the curl syntax: curl -i -F "file=@/home/pi/xxxxxx/xxxxxxx.png" http://xxxxxxx.com/upload.php

    And here's the working upload.php

    <?php
    include 'dbConfig.php';
    $statusMsg = '';
    $fileName = basename($_FILES["file"]["name"]);
    $target_path = "uploads/";
    $target_path = $target_path . basename( $_FILES['file']['name']);
    if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
     $insert = $db->query("INSERT into images (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
     if($insert){
                    $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
                }else{
                    $statusMsg = "File upload failed, please try again.";
                }
                }else{
                    $statusMsg = "Sorry, there was an error uploading your file.";
                }
    echo $statusMsg;
    ?>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条