简体   繁体   English

无法使用parse.com数据库将文件(图像)上传到php中的服务器

[英]Unable to upload file (images) onto server in php using parse.com database

I am trying to upload file onto parse.com using PHP. 我正在尝试使用PHP将文件上传到parse.com。 The code below works absolutely fine when I try upload the file(image) onto parse.com using "localhost"(Local Server). 当我尝试使用“ localhost”(本地服务器)将文件(图像)上传到parse.com时,下面的代码绝对可以正常工作。 But when I connect to main server (Linux server) and try to upload the file(image) its not uploading into parse. 但是,当我连接到主服务器(Linux服务器)并尝试上传文件(图像)时,它没有上传到解析中。 Please help me on this, Thanks. 请帮助我,谢谢。 Your help is most appreciated. 非常感谢您的帮助。

Here is the code below: (which is working fine in local server(localhost)) 这是下面的代码:(在本地服务器(本地主机)中运行正常)

HTML code HTML代码

 <table> 
    <tr>
    <td class="Lbl">Upload Picture:
     </td>
        <td>
         <input type="file" name="image">
        </td>
    </tr>
    </table>

PHP code: PHP代码:

 if (isset( $_FILES['image'] ) && !empty($_FILES['image']) ) {

    if ((($_FILES["image"]["type"] == "image/png")
    || ($_FILES["image"]["type"] == "image/gif")
    || ($_FILES["image"]["type"] == "image/jpg")
    || ($_FILES["image"]["type"] == "image/jpeg"))
    && ($_FILES["image"]["size"] < 1000000)//approx. 1000kb files can be uploaded
    ){
    //PHP Image Uploading Code

      // save file to Parse
      $file = ParseFile::createFromData( file_get_contents( $_FILES['image']['tmp_name'] ), $_FILES['image']['name']  );
      $file->save();


    $test_file = new ParseObject("Picture");
    $test_file->set("Title", $pic_txt);
    $test_file->set("URL",$file);
    $test_file->save();

      // get the object ID
     $upload_object= $test_file->getObjectId();

  }}

I have found the answer, and the solution is : 我找到了答案,解决方案是:

In Linux server, provide RWX (Read, Write, Execute) permissions to the folder which you are working with. 在Linux服务器中,为正在使用的文件夹提供RWX(读取,写入,执行)权限。 and then execute the code, it will work perfectly 然后执行代码,它将完美运行

anyways, thanks for your time buddies. 无论如何,感谢您的时间伙伴。

To give RWX permission : 授予RWX许可:

type : 类型:

sudo chmod -R 777 <file name> or <file path>

eg: 例如:

chomod -R 777 var/www

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM