Cannot Upload(post) image to server using php

Describe your issue

Cannot post image to server using php

Steps to reproduce the issue

I do all things that @Taifun said in this link below :
https://puravidaapps.com/postfile.php

Expected Behaviour

Actual Behaviour

my file doesn’t uploaded to host, just create empty files on my host with 0 sizing

my php file

<?php
/*
* Written By: Taifun
 * using parts from the "Web2SQL example" from ShivalWolf
 * and parts from the "POST any local file to a php server example" from 
Scott
 *
 * Date: 2013/Mar/05
 * Contact: [email protected]
*
* Version 2: 'dirname(__FILE__)' added to avoid problems finding the 
complete path to the script
*/

/**********************CONFIG****************************************/

 //SETTINGS//
 //This code is something you set in the APP so random people cant use it.
 $ACCESSKEY="secret";




 /********************CONFIG****************************************/

//these are just in case setting headers forcing it to always expire
 header('Cache-Control: no-cache, must-revalidate');

if($_GET['p']==$ACCESSKEY){
  // this is the workaround for file_get_contents(...)
 require_once (dirname(__FILE__).'/PHP_Compat- 
 1.6.0a3/Compat/Function/file_get_contents.php');
 $data = php_compat_file_get_contents('php://input');

 $filename = $_GET['filename'];
 if (file_put_contents($filename,$data)) {
  if (filesize($filename) != 0) {
  echo "File transfer completed.";
 } else {
  header("HTTP/1.0 400 Bad Request");
  echo "File is empty.";
 }
} else {
header("HTTP/1.0 400 Bad Request");
 echo "File transfer failed.";
}
} else {
 header("HTTP/1.0 400 Bad Request");
 echo "Access denied";     //reports if accesskey is wrong
}
?>
```

Show Your Blocks



I am also facing same problem. I think @Ka_Fa can help in this.

Hello @amirh_mrt !
I would try doing the following steps:

  1. Make sure that server is working fine. Use a tool like Post Man to make a POST request and check if that works. (this link may help)
  2. Check if the server returns the response code 200. Check the response content and code returned by the server in the Web.Got Text event block.
1 Like

Thank you very much for replying on this topic.

Can you please give a demonstration of the tools/link mentioned above?

Any related examples

hello bro . tnx
i will be try this

the responce code is 400
and its contain : File transfer failed.

Hi @arponjisan!

This Medium post covers some of the concepts.

It means that there is some issue on the server-side.
In particular, this file_put_contents($filename,$data) line is failing for some reason.

Do you get any solution for this, how we can post image or file to the server

It’s a 1 year old topic. You must search for other or open new if not got a solution.

1 Like

I opened but not response from any one, i thought he found solution on it.

@Earn_Money_online, please keep yourself in your original post. If he had found a solution, for sure he would post in this (old) topic. I’ll close this.

1 Like

the simple solution is to use ftp
https://puravidaapps.com/ftp.php
Taifun

1 Like