3

Form last 2 days i am trying to fix a issue of uploading a file in Box.net using php.

I have gone through Box.net API Documentation and copied the sample code they have given, the code that they have given- uploads file perfectly, But it redirects to that page where server response is printed(XML response).

I do not want to show user such screen, instead i would like to read those data and based on that response, display message of mine.

I have edited my code as per the guidance given by @GBD, now i am facing another issue.

The file I select does not upload , Instead it uploads some .tmp file. And when i hard code the file path in $_POST['new_file1'] it successfully uploads correct file. the file path i get is some thing like this C:\wamp\tmp\php1A.tmp not actual file path, when i echo $_FILES['new_file1']['tmp_name'].

Can any one tell me how can i get the file path from $_FILES ? So that i can pass it to $post

Following is my code:

<?php
$upload_url = 'https://upload.box.net/api/1.0/upload/i9g1fmnnddfdr4739sxvbpXXXXXXXX/480416060';
$tmpfile = $_FILES['new_file1']['tmp_name'];
$filename = basename($_FILES['new_file1']['name']);
$_POST['new_file1'] = '@'.$tmpfile;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); 
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
<form action=""
  enctype="multipart/form-data" accept-charset="utf-8" method="POST">
<input type="file" name="new_file1" />
<input type="text" name="share" value="1" />
<input type="submit" name="upload_files" value="Upload File" />
</form>

Please help me out.

Thanks in advance.

2
  • Ensure you have the right Content-Type and/or enctype as per the Box API documentation. Commented Dec 4, 2012 at 17:47
  • It gives you all the data for debuging. upload_no_files_found means exactly what it states and you should've checked if you actually supply any file in a request. If you would do that, you'd find that you actually don't supply any file as in PHP files are in $_FILES and not in $_POST. Commented Dec 5, 2012 at 11:16

1 Answer 1

1

Try

<?php

$tmpfile = $_FILES['new_file1']['tmp_name'];
$filename = basename($_FILES['new_file1']['name']);

$_POST['new_file1'] = '@'.$tmpfile;

$upload_url = 'https://upload.box.net/api/1.0/upload/i9g1fmnnddfdr4739sxvbpXXXXXXXX/480416060';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); 
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply.But still it does not upload the correct file,instead it uploads some .tmp file.Also $tempfile has value C:\wamp\tmp\php1A.tmp not the actual file location. Please any changes i need to do?
I am facing the same problem, did you get any solution for the above point?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.