dougou5852 2019-04-13 18:17
浏览 65

PHP:文件已上载,但不会从临时目录中移出。 我该如何解决?

I am trying to upload an image to server (I am using Google Cloud Virtual Machine) that the PHP gets from a Python script (I intend to retrieve the images from a Raspberry Pi camera sensor, but for now, I am sending a placeholder image to test the functionality of my script) that sends the image along with other parameters through a POST request. However, while the image does get uploaded, it does not get moved to a new location as it is shown in the Output I have provided below along with the code.

A question found here: php uploading a file says it is working but does not actually upload a file does have a similar problem, however the suggested solution there did not help me.

Here's the code that implements the file upload system.

PHP Upload File code:

    //Upload the image   
    $uploadDir = "/home/username/directory/";
    $uploadFile = $uploadDir . basename($_FILES["myimage"]["name"]);

    if(is_uploaded_file["myimage"]["tmp_name"]) 
    {
        echo "File has been UPLOADED
";                          
        if(move_uploaded_file($_FILES["myimage"]["tmp_name"],$uploadFile))      
        {      
            echo "File has been MOVED";
        } 
        else     
        {       
             echo "File has NOT been MOVED";
        }
    }     
    else     
    {               
        echo "File has NOT been UPLOADED";
    }

Python code which sends a request to the PHP above:

    import requests

    def postData(directory):
        activity = "Someone walked in"
        url = 'http://35.198.114.146/index.php/sensor_readings/postdata?activity=' + activity
        image = {'myimage': open(imagePath,'rb')}

        r = requests.post(url,files=image)
        print(r.text)

    imagePath = 'cam_images/test.png'
    postData(imagePath)

Output:

    File has been UPLOADED
    File has NOT been MOVED

I have been stuck on this problem for weeks and I am not sure on what to do. Any kind of help is appreciated. Should you need more details or code, feel free to ask me.

Thank you in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么在stm32门禁成品上增加记录功能
    • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
    • ¥50 NT4.0系统 STOP:0X0000007B
    • ¥15 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 解riccati方程组