Jump to content

M.O.S. Studios

Members
  • Posts

    304
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

M.O.S. Studios's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

5

Community Answers

  1. So, after giving up on the documentation I gave postman.com a gander. All the parameters are supposed to be sent within the URL, and the file as the only information in the post field. They also allow you to send plain text, and they will encode it for you. So here is what I did: $uploadPath = str_replace("/".basename($args['uploadPath']), '', $args['uploadPath']); $accessToken = getPcloudToken(); $query = array('filename'=>'file.csv', 'nopartial'=>'1', 'path'=> $uploadPath); $product_data = $args['product_data']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pcloud.com/uploadfile?'.http_build_query($query)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $product_data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain', 'Authorization: Bearer '.$accessToken)); curl_exec($ch); curl_close($ch); I was able to take the whole temp file creation out. so that was nice
  2. Can anyone make heads or tales of this? I am playing around with pCloud. The Pcloud file upload documentation is kinda vague. they don't explain where or how to attach the file, just how to name it, and where to put it. They even have instructions on how to send it as binaries. but that is also kind of vague. Can someone see what I am missing? This code is supposed to take a string, create a temp file, and then upload it. at the moment, it uploads a file with the right file name, but only contains two dashes $uploadPath = 'uploadpath'; $accessToken = AccessToken; $product_data = fopen('php://memory', 'r+'); fputs($product_data, 'content string'); rewind($product_data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pcloud.com/uploadfile' ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, array('filename'=>'test.csv', 'data'=>$product_data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data', 'Authorization: Bearer '.$accessToken)); $result = curl_exec($ch); var_export(curl_error($ch)); var_export($result); curl_close($ch);
  3. Thanks for the reply. I only changed the URL from the OwnCloud host to the new one. When I ran the terminal, it worked perfectly. I rebooted and tried from a private browser that doesn't keep the cache. When I did it from the terminal, I did it from port 80, and it worked
  4. Hey everyone, Here is a bit of a weird one. I set up ownCloud using a PAAS service and it is running well. However, when I try to use curl from PHP, I keep getting an error that says "Failed to connect to THEURL port 80: No route to host" This is weird for two reasons. 1. I also tried uploading it from my computer's terminal, using curl, and that 2. Until about a day ago, I had my own cloud on a shared host, and the PHP code worked just fine. Here is the PHP code I used: function uploadToOwncloud($args = array()){ $uploadPath = $args['uploadPath']; $product_data = fopen('php://memory', 'r+'); fputs($product_data, $args['product_data']); rewind($product_data); $user = $args['user']; $pass = $args['password']; $url = "MYOWNCLOUDURL.COM/remote.php/webdav" .urlencode($uploadPath); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass"); curl_setopt($ch, CURLOPT_PUT, 1); curl_setopt($ch, CURLOPT_INFILE, $product_data); curl_setopt($ch, CURLOPT_INFILESIZE, fstat($product_data)['size']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary $curl_response_res = curl_exec ($ch); var_export(curl_error($ch)); return; } Here is the terminal command I used: curl -u "user:password" -T test.txt "http://myowncloudurl.com:80/remote.php/webdav/text.txt" I tried adding my domains to the whitelist, and turning off the fire wall Thanks
  5. Hey guys, I have a script I’m working on, and I was curious if I can do the following: 1. user clicks button on browser, that sends a request to the server using ajax 2. the server creates a zip file and stores it in php://memory 3. the browser get the needed information to initiate a download of the zip file. can this be done? I suspect I have to physically save the file on the server, and delete it after; which I would like to avoid
  6. Hey everyone, I am trying to take information from a DB and convert it into a string that has CSV values. some of the values have commas and double quotes, which messes up the end product. is there a way to escape the string so it is rfc 4180 compliant? I don’t want to create a file. I know I can use str_putcsv along with php://temp; but ideally I wouldn’t do that. Mostly because my shared hosting has issues php://temp thanks in advance!
  7. I might have worded it wrong. I want it so that if any of those three methods have an exception, it will bubble up to the try/except in the _construct method. for example: class myclass{ public function func1(){ //line of code that creates fatal error } function __contruct(){ try(){ $this->func1(); }catch(Exception $e){ echo "found a error"; } } } the above will work only if the exception is thorwn within the scope of func1(). if func1() calls an external function that throws an exception, it wont catch it. It doesn't "bubble up". if I change it to: class myclass{ public function func1(){ try(){ buggyFunc(); }catch(Exception $e){ throw new Exception($e); } } function __contruct(){ try(){ $this->func1(); }catch(Exception $e){ echo "found an error"; } } } this works. The problem is, if you look back to my original example: I don't want any subsequent functions to run if the previous function had an error. At the same time, I don't want to a script filled with "try/catch/throw" commands
  8. Hey Everyone, Odd question. I am working with a class that runs methods when a new instance is created. Is there a way to catch any errors thrown within the methods? Here is the code: function __construct(){ try{ $this->val1 = $this->func1; $this->val1 = $this->func2; $this->val1 = $this->func3; }catch(Exception $e){ $this->notes($e); $this->errors = true; } } Ideally, if method "func1" throws an error at anypoint within it, then it will be caught by "catch" in _construct. Is this possible, or do I need to add "try/catch" to each method?
  9. This looks awesome! Probably just what I need. stupid question: I’m on shared hosting with no terminal. So that means no composer. Do you think I can install this another way?
  10. Hey Everyone, I am working on a short script that transfers information from one source to another. Both have a ReST api. I was curious if anyone knew any resources that can make that easier. Ideally, it would be a php file I can use to make an object for each API? Any ideas?
  11. function spamTest($header){ $output_array = preg_grep('/^(X-Spam-Score:)\s([-+]?\d{1,3}\.\d)?/i', explode("\n", $header)); list($xSpamScore, $score) = explode(": ", $output_array[array_key_first($output_array)]); return ($score < 5); } I ran the email header into this and it seems to work.
  12. Ok! So I have been doing the following research: I watched this video to understand how these protocols work I took a look at the headers you posted I sent my php script some real, and spoofed emails I now have a better understanding of what you were explaining to me. My email server does all the checking for me and puts the results into the header of the email. All I need to do is create a php script that checks the headers to see if it passed. Thus the regex code. Is that correct?
  13. Is it really just regex? That’s way easier than I thought it was going to be. I assumed I needed to grab some kind of address, then verify it using a service. thanks! I will look more into this andmuodate the post
  14. Sorry, I meant can you recommend a good php library that can verify its not a spoof once I get the headers.
  15. Yeah, That's so amazing to hear. Do you have any libraries you can recommend? When I look up this topic, the majority of stuff is about validating the content of an outgoing email, as opposed to what I am looking for.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.