2

Where ever and on each site I look, they say wrong file path cause this error, But I am sure my path is correct and it works last night why not tonight??!!

To prove that the path is correct, file_exists($path) return true.

I want to send file using Curl and I get failed creating formpost data. The path to file which I give to Curl is like below:

define('ASSET_PATH', dirname(dirname(dirname(__FILE__))) . '/asset');

$postfields = array(
    'chat_id'   => $user->user_id,
    'caption'   => $asset->caption,
    'duration'  => $asset->duration,
    'video'     => "@" . ASSET_PATH . "/video/" . $asset->name,
);

And when you see the value of $postfields['video'], the output is:

/home/hosseins/domains/my_domain/public_html/telegram/asset/video/Bottle_Bank.mp4

Further Code

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

$result = curl_exec($ch);
echo curl_error ( $ch ); //return failed creating formpost data
echo '<br />' . ASSET_PATH . "/video/" . $asset->name; //return named path
curl_close($ch);

Is there anything wrong with my addressing or problem coming from some where else?
Dudes I'm stuck here, any help will be appreciated.
Thanks in advance

1

2 Answers 2

1

Curl treat @ as path to file, means when you use @ at first of string, that string considered as file path. So here Curl think my caption is path to file and he can't find that absolutely.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have not changed the code and stopped working, then it may be the permission of the file that has changed. Make sure the file is with the necessary permissions.

You can also look here.

3 Comments

Thanks for answer, I check the permission and they're set on 755, so no problem here, also I checked that link before and according to tha my path is correct as also we see the path in my question.
Have you tried with other files? Maybe it has something wrong with this file, maybe this file is too big. That's all I can think, I never did upload in that way, I only did file upload writing the multipart/form-data manually.
Yea I try multiple file but no difference, the point is it ran successfully last night. Codes magic!! Thanks anyway for your time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.