Skip to content

Instantly share code, notes, and snippets.

Simon simonbernard

Block or report user

Report or block simonbernard

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
simonbernard / php-curl-download-and-revert-curlopt_file.php
Created Feb 14, 2014
It took me some time so I would like to share with you: How-to download a file with PHP's cURL and afterwards continue with other cURL requests which return their output as usual.
View php-curl-download-and-revert-curlopt_file.php
$fh = fopen('/your/target/file', 'w');
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_URL, 'http://your/download/url');
// revert it
curl_setopt($this->ch, CURLOPT_FILE, STDOUT);
fclose($fh); // don't forget to close the handle
simonbernard / php-curl-upload.php
Last active Jan 28, 2016
Ever tried to upload a file via PHP's cURL? Here is how I did it. I hope it well help someone.
View php-curl-upload.php
// client side upload
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data")); // i guess it's the default
curl_setopt($ch, CURLOPT_URL, 'http://url/to/upload');
curl_setopt($ch, CURLOPT_POST, true);
$file = curl_file_create('/path/to/your/');
$post = array('anyParameterYouNeed' => 'anyValue', 'fileArrayIndexOnServer' => $file);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $postData);
// and on the server side it looks like this
simonbernard / angularjs-contenteditable.js
Last active Aug 29, 2015
I spent some reasonable time finding out, how to properly set-up a contenteditable directive in angularjs. What I wanted was a directive that preserves all new-line characters but I did not want any HTML code in the model. I ended up with below directive which replaces the tags with new-line characters. I used this directive on a contenteditable…
View angularjs-contenteditable.js
app.directive('contenteditable', function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
// model -> view
ngModel.$render = function() {
You can’t perform that action at this time.