Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues using cURL through PHP for HTTP POST with $_FILES
    primarykey
    data
    text
    <p>Essentially, what I have to do is take a HTTP Post, and save the file on a first server, and then forward the post to a second server which saves the file again and then generates an email with the file as an attachment. Presently, I have it working where I send the post to the second server, and it creates the email and sends it out, so that's not an issue. </p> <p>However, when I tried adding the first server in there, I cannot get it to send at all, or print out a meaningful result. Here is the code for the send/receive script: </p> <pre><code>&lt;?php $uploaddir = '/home/www/myfirstsite.com/3d/'; $uploadname = basename($_FILES['file']['name']); $uploadfile = $uploaddir . $uploadname; if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { echo "OK\n"; } else { echo "ERROR\n"; } echo "&lt;br&gt;"; $url = 'http://mysecondsite.com:12345/receive_scan.php'; //I use port 12345 because most of the important ports are being used already. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $_FILES); curl_setopt($ch, CURLOPT_FAILONERROR,true); $result='Result: '.curl_exec ($ch); echo $result; echo curlerrno($ch); echo curlerror($ch); curl_close ($ch); </code></pre> <p>Presently, when I send a HTTP post request, it prints out this:</p> <pre><code>OK Result: </code></pre> <p>The code that I use to send the HTTP post request is this:</p> <pre><code>&lt;html&gt;&lt;body&gt; &lt;form enctype="multipart/form-data" action="http://myfirstsite.com/receive_scan.php" method="POST"&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="100000" /&gt; Choose a file to upload: &lt;input name="file" type="file" /&gt;&lt;br /&gt; &lt;input type="submit" value="Upload File" /&gt; &lt;/form&gt; </code></pre> <p>The code on the second server that receives, which works with this code above if I just change the site, is this: </p> <pre><code>&lt;?php $uploaddir = './scans/'; $uploadname = basename($_FILES['file']['name']); $uploadfile = $uploaddir . uploadname; echo "File Received\n"; if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { echo "OK\n"; } else { echo "ERROR\n"; } shell_exec("bash sendmail.bash ".$uploadfile." ".$uploadname); ?&gt; </code></pre> <p>The sendmail.bash is just a script that usings msmtp to send an email to my email. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload