I need to change the upload_path using an external url.
Instead of using the script below
$config['upload_path'] = 'assets/images/shop_images';
I need to upload the images in a different url like this
$url = 'www.mydomain.com/images/upload';
$config['upload_path'] = $url;
How can I do it?
That is not the correct way, However you can try the below method:
$ch = curl_init("http://www.remotepage.com/upload.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CUROPT_POSTFIELDS, array('fileupload' => '#'.$_FILES['theFile'] ['tmp_name']));
echo curl_exec($ch);
Also, you need to have a php script on the remote server that should
allow(permit) you to upload file to the desired location on the remote server as it could be a security concern.
You can refer: Remote Server File Upload
Related
I am working on codeigniter and I am doing a POST request curl for another project that is located on another server that is on another network.
This is my code.
controller from my webpage
function submit_form() {
error_log("data: ". $_POST);
$data = $this->input->post('data');
$data = json_decode($data,true);
error_log("data id: ".$data['idParceiro']);
// where are we posting to?
$url = 'http://mywebdomain/ncsync/Sync/getLogin';
$fields = array('idParceiro' => $data['idParceiro']);
// build the urlencoded data
$postvars = http_build_query($fields);
// open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
// execute post
$result = curl_exec($ch);
The error_log on the server that receives the post is not being printed, hence I conclude that nothing is coming.
this is my .htaccess in my server that receive the request in folder /application
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Note: This works on localhost when I am on the same network as the server to which I am requesting.
Can help me?
I use curl with laravel and I need to launch a function inside a controller.
but when I put
dd('test');
after the namespace it's print.but when I try with the function a have a session expired
this is the code for the curl
// Préparation des données
$data = [];
$data["code__client"] = "VERTDIS13";
$data["status"] = "90";
$data["numero__incident"] = "INC544842";
// On tranforme le tableau PHP en objet JSON
$data = json_encode($data);
// Envoi au serveur
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost:3000/notification/server");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "data=" . $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
$server_output = curl_exec($ch);
$error = curl_error($ch);
if($error!=""){ dd($error);}
curl_close($ch);
// Ici pour tester j'affiche ce que le serveur renvoi
return $server_output;
inside the controller I tried to print data but it doesn't work
do you see the issue ?
thanks for help .
The session expired response sounds to me as if you are performing multiple consecutive curl requests to your application. If that's the case and your application depends on session cookies you can create a simple text file that is read and writeable to the script that does the curl requests, and add this to your code:
$cookie_file = "/the/path/to/your/cookiefile.txt";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
Change the path in $cookie_file to the full filesystem path of the text file you create and curl will persist session cookies that are being returned with responses and use them in consecutive requests.
For this to work I think you should remove the line
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
because this would advise curl to ignore the cookies in the file.
Besides that I think the line
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
is also obsolete, because you don't provide basic auth credentials in your curl request.
I presume you extract data from within the application?
To me, it looks like CSRF token is missing or is in fact invalid.
for ($i = 0; $i < $metas->length; $i++){
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'csrf-token')
$csrfToken = $meta->getAttribute('content');
}
$headers = array();
$headers[] = "Cookie: X-CSRF-Token=$csrfToken";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
More about CSRF & cURL
Give this a go
I have added FB share dialog to share images on facebook. I have tried all possible solutions but its still not fetching image. After sometime for some posts it works but not most of the times.
I have forcefully scraped the urls using php curl
$current_url = get_permalink();
$curl = 'https://graph.facebook.com/';
$return = getCurlRequest($curl,'id='http://viralsyndicator.com/best-spring-fishing-lures-of-2018-bass-pro-shops-challenge/'&scrape=true&access_token=token');
function getCurlRequest($url,$postdata=""){
//echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:','Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
//echo '<pre>';print_r($response);
curl_close($ch);
if ($response == false){ return false;}
return $response;
}
This page always has og:image meta tag but still it does not work. When I go to fb debugger tool and I debug it, first time it says og:image should be provided, scraping it after 2-3 times it starts working.
I have tried og:image:width properties as well.
I am using wordpress plugin to share, I have used FB.ui as well manually and it worked for sharing but I am also using FB comment plugin and when I am commenting and checking checkbox to post on fb as well, its not publishing image and I don't know how to use FB comment plugin manually similarly share to fetch correct image instead of logo.
FB.ui({
method: 'share',
href: '<?php echo $postUrl; ?>',
picture: "http://viralsyndicator.com/wp-content/uploads/2018/02/0-199-670x377_c.jpg",
title: 'title',
description: '<?php echo $decodedPostTitle; ?>',
}, function(response) {});
I dont know how to solve this FB issue.Please help guys.
Thanks
Trying to get square connect API image upload working using PHP.
I used the square connect API guide: docs.connect.squareup.com/api/connect/v1/#post-image
Tried two different ways based on what I found on StackOverflow and Google searching.
Method 1) regular curl request:
https://gist.github.com/delalis/17c3c111e3b42df127ed
Method 2) using CURLFile (php >=5.5 only)
https://gist.github.com/delalis/5c7ecc2aaa024927b360
Both methods gave me this empty reply from server error:
Error: "Empty reply from server" - Code: 52
I am able to connect to square to do other functions no problem, image uploading however is proving to be quite difficult!
Any help would be greatly appreciated.
Here's a working PHP example that I usually share with people:
https://gist.github.com/tdeck/7118c7128a4a2b653d11
<?php
function uploadItemImage($url, $access_token, $image_file) {
$headers = ["Authorization: Bearer $access_token"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "#$image_file;type=image/jpeg"]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$return_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "POST to $url with status $return_status\n";
curl_close($ch);
return $data ? json_decode($data) : false;
}
print_r(
uploadItemImage(
'https://connect.squareup.com/v1/me/items/ITEM_ID/image',
'ACCESS_TOKEN',
'IMAGE_FILE.jpg'
)
);
?>
Im looking for a way to send remotely content(text and image ) by xmlrpc to wordpress but i couldn't find yet, im going to sent remotely content (text and image) over 100 post per minute to wordpress, whats the best way to do it? thanks so much
Use XMLRPC. Something like this:
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);