LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   cURL php upload posting $_FILES[file][name] array creation (https://www.linuxquestions.org/questions/programming-9/curl-php-upload-posting-%24_files%5Bfile%5D%5Bname%5D-array-creation-802298/)

devwink 04-15-2010 08:31 PM

cURL php upload posting $_FILES[file][name] array creation
 
Hi All,

I'm uploading from https site to a remote https site.

I'm having trouble using method POST multipart/form-data as firefox sees this unencrypted post data and aborts the operation.

I was thinking of using curl (details below) but i get "undefined index : file in upload.php. (as these super(or automatic) globals arn't passed.

In the fetch1.php below, i'm attempting to post variables and recreate these globals on the new server.

I cannot get it to register the global variables

upload form -> fetch1.php(on same server) -> upload.php (remote ssl)

fetch1.php
Code:

<?php
 // include_once('file://///Mainxp/shareddocs/psd.php');
header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');
// set to remote script to call

$remote = 'https://example.com.au/upload.php';
$remote .= '?job_id=' . $_GET['job_id'];
$basename = basename($_FILES['file']['name']);
$remote .= '&basename=' . $basename;

$ch = curl_init();
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $remote);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/gd_bundle.crt");
curl_exec($ch);
curl_close($ch);
?>


then upload.php tries to extract post variables and create globals


Code:

<?php
 
 global($_FILES['file']['name']) =$_GET['basename'];

if($_FILES['file']['error'] == UPLOAD_ERR_OK){

$path = '/var/www/html/uploads/';                                                        //destination upload directory

$path .= basename($_FILES['file']['name']);                                        //concats new path to base file name (pulled from $_files array
 
 if(move_uploaded_file($_FILES['file']['tmp_name'], $path)){
      //upload successful
  }
}
?>



any help would be greatly appreciated.. thanks

Sergei Steshenko 04-16-2010 04:57 AM

Quote:

Originally Posted by devwink (Post 3937084)
...
In the fetch1.php below, i'm attempting to post variables and recreate these globals on the new server.
...

I am not a PHP guy, but recreating global variables smells terribly fishy - regardless of language.

devwink 04-16-2010 07:19 AM

thanks Sergei
I'm uploading images from my https://www.example.com.au (commercial shared server) to my https://example.net.au because commercial shared server doesn't have APC enabled and I want to getprogress , (that part is ajax and it works fine with curl )

I also want to resize and store large images and avoid bandwith/storage if all goes as planned.

I also hope to load share using ping to establish the home server loads.

May be I should write it to mysql and read it again at the other end, but i still have to pass one common variable to reference the upload.

I Want the progress bar to stay nested in the page my form is on one server and is passing url variables to another server (also https but different certificate)

My commercial shared server host will not put a shared ssl in the domain.(and still provide a seal).

I was thinking of dropping the seal as I intend to outsource the e-commerce bit.

It all works fine on I.E, but firefox is a bit more safe savy.

Cheers


All times are GMT -5. The time now is 06:09 AM.