28, May 2012
copy a file from remote with cUrl - webmaster forum
Navigation
Webdigity Services
Pagerank Monitor
Whois Tool
Web Design Gallery
Webmaster Forums
Webmaster Directory
Tutorials Database
Webmaster Forums
WebDigity Community
Topsites network news ...
Forum Contests
Forum Lounge
New Member Introductions
Tech News
User Forums
aStatSpam forum
Computers
3rd-Party Scripting
Leet Link Directory
The 100 Lists Website ...
Design and Layout
Newbie webmaster
Graphics & Multimedia
Adobe Photoshop
Macromedia Flash & Act...
Web Page Design
HTML & XHTML
CSS
Accesibility issues
Website & Graphic Revi...
Web Development
PhP
ASP & .NET
Java & JSP
Official Java News
JavaScript
XML - XSLT
Databases
MySQL
Security
Web hosting talk
Hosting companies
Domain names
Configuring your server
Apache web server
Marketing your site
CPC programs
Chitika eMiniMalls
CPM programs
Affiliate programs & o...
Web site promotion
Promotion techniques
Search Engine Optimiza...
Google SEO
Promoting & building a...
Marketplace
Advertise your services
Sell your site
Sell a domain name
Request services
Hire people
Link trading requests
[
Home
|
Help
|
Search
|
Forum's Shop
|
Archive
|
Login
|
Register
|
Webmaster Directory
]
Web
www.webdigity.com
Hide the search bar
Whois database search :
Domain :
Use the whois database tool to retrieve information on any top level domain you are interested in.
Webdigity Webmaster Forums
>
Web Development
>
PhP
Topic:
copy a file from remote with cUrl
« previous
next »
Pages: [
1
]
Author
Topic: copy a file from remote with cUrl (Read 3517 times)
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
on:
Aug 09, 2006, 09:02:02 am »
Hello,
I need to copy a file without using the php function "copy".
I got this example sometime before from Nick:
Code:
<?php
$ch
=
curl_init
(
"http://www.bergtoys.info/"
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
50
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_FOLLOWLOCATION
,
true
);
$curl_ret
=
curl_exec
(
$ch
);
$data
=
curl_getinfo
(
$ch
);
curl_close
(
$ch
);
where $data is the data I collected via curl, now I need to save this data into a file (image) on the server, do I need to use a fopen function now?
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #1 on:
Aug 09, 2006, 09:52:49 am »
Yes, but in the code you posted, the contents of the file are stored in the $curl_ret variable.
The $data has the info about the session (headers, etc)
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #2 on:
Aug 09, 2006, 09:57:02 am »
Quote from: Nikolas on Aug 09, 2006, 09:52:49 am
Yes, but in the code you posted, the contents of the file are stored in the $curl_ret variable.
The $data has the info about the session (headers, etc)
OK
do you have an example how to handle error's with curl (since there are no booleans possible like "if (!copy(..."
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #3 on:
Aug 09, 2006, 09:58:27 am »
I check if the strlen($curl_ret) is bigger than 0 and the response header (right now is in the $data)
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #4 on:
Aug 09, 2006, 10:05:46 am »
Quote from: Nikolas on Aug 09, 2006, 09:58:27 am
I check if the strlen($curl_ret) is bigger than 0 and the response header (right now is in the $data)
what about this function?
Code:
<?php
function
copy_with_curl
(
$url
) {
$ch
=
curl_init
(
$url
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
50
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_FOLLOWLOCATION
,
true
);
$curl_data
=
curl_exec
(
$ch
);
if (
curl_errno
(
$ch
) ==
0
) {
if (
$fd
= @
fopen
(
$this
->
thumbnail_path
,
"wb"
)) {
fwrite
(
$fd
,
$curl_data
);
fclose
(
$fd
);
$err
=
true
;
} else {
$err
=
true
;
}
} else {
$err
=
true
;
}
curl_close
(
$ch
);
return
$err
;
}
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #5 on:
Aug 09, 2006, 10:10:44 am »
Nice, but you have a small error
The replacement should be this :
Code:
<?php
function
copy_with_curl
(
$url
) {
$ch
=
curl_init
(
$url
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
50
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_FOLLOWLOCATION
,
true
);
$curl_data
=
curl_exec
(
$ch
);
if (
curl_errno
(
$ch
) ==
0
) {
if (
$fd
= @
fopen
(
$this
->
thumbnail_path
,
"wb"
)) {
fwrite
(
$fd
,
$curl_data
);
fclose
(
$fd
);
$err
=
false
;
} else {
$err
=
true
;
}
} else {
$err
=
true
;
}
curl_close
(
$ch
);
return
$err
;
}
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #6 on:
Aug 09, 2006, 10:12:16 am »
yes thats right twice a true, thanks
is this curl a standard on linux shared hostings?
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #7 on:
Aug 09, 2006, 10:14:50 am »
Quote from: olaf on Aug 09, 2006, 10:12:16 am
yes thats right twice a true, thanks
is this curl a standard on linux shared hostings?
I am not sure about this, but you can check it :
Code:
<?php
if ( !
extension_loaded
(
'curl'
) )
echo
'Problem....'
;
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #8 on:
Aug 09, 2006, 10:40:31 am »
Quote from: Nikolas on Aug 09, 2006, 10:14:50 am
I am not sure about this, but you can check it :
Code:
<?php
if ( !
extension_loaded
(
'curl'
) )
echo
'Problem....'
;
is there only a curl extension?
(then I'm able to check this via phpinfo())
«
Last Edit: Aug 09, 2006, 11:04:59 am by olaf
»
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #9 on:
Aug 09, 2006, 11:38:01 am »
yes, curl is available on all shared hosts I'm using (6 diff. configurations)
and I learned that there are much more configuration settings then with functions like fopen... COOL!
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #10 on:
Aug 09, 2006, 11:54:25 am »
Quote from: olaf on Aug 09, 2006, 11:38:01 am
and I learned that there are much more configuration settings then with functions like fopen... COOL!
Of course. Actually curl is an 'interface' to fopen, and it uses fopen to work....
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #11 on:
Aug 09, 2006, 12:29:25 pm »
Quote from: Nikolas on Aug 09, 2006, 11:54:25 am
Quote from: olaf on Aug 09, 2006, 11:38:01 am
and I learned that there are much more configuration settings then with functions like fopen... COOL!
Of course. Actually curl is an 'interface' to fopen, and it uses fopen to work....
strange is that the setting "allow_url_fopen" is not blokking here...
I am a metal monkey!
Administrator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits
Members referred : 3
«
Reply #12 on:
Aug 09, 2006, 12:34:00 pm »
This is propably because curl is using fopen from the Zend engine level (php.ini restrictions are not a problem there)
Trial and Error my two best teachers
Join us @ facebook
or
twitter
Last blog :
Butterfly Marketing 2.0
Global Moderator
Community Supporter
?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits
Members referred : 374
It's time to use PHP5!
«
Reply #13 on:
Aug 09, 2006, 12:38:27 pm »
Quote from: Nikolas on Aug 09, 2006, 12:34:00 pm
This is propably because curl is using fopen from the Zend engine level (php.ini restrictions are not a problem there)
Yes that's possible...
Trackback URI for this entry :
http://www.webdigity.com/trackback.php?topic=3588
Tags :
php
curl
zend
linux
Bookmark this thread :
Digg
Del.icio.us
Dzone
more....
Pages: [
1
]
Webdigity Webmaster Forums
>
Web Development
>
PhP
Topic:
copy a file from remote with cUrl
« previous
next »
Jump to:
=>Personal Messages
=>My Subscriptions
=>Profile Settings
=>Account Settings
=>Look and Layout Settings
=>Unread Posts
=>Unread Replies To My Posts
=>Affiliate Program
=>Forum's Shop
=>Arcade
Category: WebDigity Community
=> HumanWorks network news & feedback
===> Clickbank Contextual Script Support
=> Forum Contests
=> Forum Lounge
===> New Member Introductions
===> Tech News
===> Google Forum
=> User Forums
Category: Design and Layout
=> General webmaster discussions
=> Graphics & Multimedia
===> Adobe Photoshop
===> Macromedia Flash & Actionscript
=> Web Page Design
===> HTML & XHTML
===> CSS
===> Accesibility issues
=> Website & Graphic Reviews
Category: Web Development
=> PhP
===> PHP classes @finalwebsites.com
=====> Easy PHP Upload
=====> Access_user Class
=====> Validate_fields Class
=====> DB_cart Class
=====> Miscellaneous scripts or snippets
=====> PHP Whois script
=====> 3rd party modifications
===> Php User Class
=> JavaScript
=> Databases
===> MySQL
=> Security
=> Miscellaneous Languages
===> ASP & .NET
===> Java & JSP
=====> Official Java News
Category: Web hosting talk
=> Hosting companies
=> Domain names
=> Configuring your server
===> Apache web server
Category: Monetizing your site
=> General Business
=> CPC programs
===> Adsense
===> Chitika eMiniMalls
=====> Official news from Chitika
=====> Ad placement reviews
=====> eMiniMalls feedback and suggestions
=> CPM programs
=> Affiliate programs & other revenue models
Category: Web site promotion
=> Promotion techniques
=> Search Engine Optimization
===> Google SEO
=> Promoting & building a forum
===> SMF moding & promoting
Category: Marketplace
=> Advertise your services
===> Web Hosting Deals
=> Sell your site
=> Sell a domain name
=> Request services
=> Hire people
=> Link trading requests
User Area
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 28, 2012, 02:54:35 pm
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Donate to our community, and get a permanent link back to your site!
Forum Statistics
Total Posts:
62.871
Total Topics:
11.036
Total Members:
21.466
Tutorials
:
58
Resources
:
929
Designs
:
395
Latest Member:
zhangzhiwu
150 Guests, 4 Users online :
Googlebot
,
Msnbot
,
hobbit
,
Yahoo crawler
36 users online today:
hobbit
,
AndyPR
,
hirewebdesigner
,
Markirosyan
,
thietkelogo
,
nmagsbyshalo
,
Nikolas
,
X-man
,
zhangzhiwu
,
jackandrew
,
thergery
,
anytecable
,
jarankepang
,
yosa
,
CarlJHash
,
Proaxxs-peter
,
blackmilk
,
tfyjgh
,
ifuturz
,
froz
,
golamkayes
,
ketnoimang
,
charles0029
,
SEO AUS
,
Maximlis
,
zoii
,
mabdwasoft
,
jackson12
,
rashmimaharjan
,
Kim_smith
,
iplaytheme
,
bjland5
,
sobbin
,
skbj329
,
w66266507
,
nathan.joshua
Recent topics
Re: offshore VPS hosting...
What is the Strong and hard...
Re: Hosting for pictures?...
Re: What are Meta Tags ....
Re: Linux Servers along wit...
Re: Unlimited hosting...
Re: Hosting with SSD ...
Reliable domain registratio...
HumanWorks Network
Technology news
Webmaster articles
Sublime web directory
RSS Feed directory and viewer
Web Design Gallery
·
Whois Lookup
·
Pagerank
·
Tag Browsing
·
Lo-fi version
·
Syndication
·
Webmaster forum history
·
Advertise
Developed by
HumanWorks
© 2005 - 2012
Webdigity webmaster community
·
sublime directory
Webdigity Webmaster Forums | Powered by
SMF 1.0.12
. © 2001-2005,
Lewis Media
. All Rights Reserved.