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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测