php-general Digest 11 Dec 2009 18:10:06 -0000 Issue 6482
Topics (messages 300381 through 300388):
Re: file_get_contents ($file) works -- file_get_contents ($url) returns false
300381 by: Gaurav Kumar
Re: Upload dir
300382 by: Gaurav Kumar
300383 by: kranthi
300384 by: kranthi
300385 by: Richard Quadling
300386 by: Ashley Sheridan
Re: Using Curl to replicate a site
300387 by: Ashley Sheridan
move_uploaded_file
300388 by: Roberto
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
A very typical problem. Good you sent the error message.
This problem can be caused due to one of the following-
1. I have faced similar problem due to local firewall settings.
2. Try some other domain; i.e. other than google com. Try some of the local
area website with a particular page like www.somedomain.com/somefile.html
3. Some times the remote host does not allow you to connect to get the file
contents.
4. # 3 can be either way round from both the ends a) you host server does
not allow external connections b) Remote host does not allow anonymous
connection.
Hope this helps..
Gaurav Kumar
blog.oswebstudio.com
On Thu, Dec 10, 2009 at 9:01 PM, René Fournier <[email protected]> wrote:
> I thought error_reporting would display them, but I guess php.ini had them
> suppressed. Anyway, with:
>
> <?php
>
> error_reporting(-1);
> ini_set('display_errors', 1);
> set_time_limit(0);
> var_dump (file_get_contents ('http://www.google.com'));
>
> ?>
>
> I get:
>
> Warning: file_get_contents(http://www.google.com): failed to open stream:
> Operation now in progress in /____/____.php on line 7 bool(false)
>
> Does that help with the diagnosis?
>
>
> On 2009-12-10, at 12:28 AM, Richard Quadling wrote:
>
> > 2009/12/9 René Fournier <[email protected]>:
> >> It is, and I use curl elsewhere in the same script to fetch remote
> content.
> >> This exact same function works fine on my MacBook Pro (10.6 client, PHP
> 5.3), and *was* previously working fine under Server 10.4.11 and PHP 5.3,
> >>
> >> On 2009-12-09, at 11:10 PM, laruence wrote:
> >>
> >>> try
> >>> wget http://www.google.com in your command line to see whether the
> network is reachable
> >>>
> >>> LinuxManMikeC wrote:
> >>>>
> >>>> On Wed, Dec 9, 2009 at 8:02 AM, LinuxManMikeC <
> [email protected]> wrote:
> >>>>
> >>>>> On Wed, Dec 9, 2009 at 6:45 AM, René Fournier <[email protected]>
> wrote:
> >>>>>
> >>>>>> Strange problem I'm having on Mac OS X Server 10.6 running PHP 5.3.
> Any call of file_get_contents() on a local file works fine -- the file is
> read and returned. But any call of file_get_contents on a url -- any url,
> local or remote -- always returns false.
> >>>>>>
> >>>>>> var_dump (file_get_contents
> >>>>>> ('http://www.google.com/')<http://www.google.com/%27%29>
> );
> >>>>>>
> >>>>>> bool(false)
> >>>>>>
> >>>>>> I've checked php.ini, and the obvious seems okay:
> >>>>>>
> >>>>>> allow_url_fopen => On => On
> >>>>>>
> >>>>>> Any ideas?
> >>>>>>
> >>>>>> ...Rene
> >>>>>>
> >>>>>
> http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
> >>>>>
> >>>>>
> >>>>
> >>>> "I've checked php.ini"
> >>>> Right, must remember not to reply to stuff till I'm awake. :-D
> >>>>
> >>>> --
> >>>> PHP General Mailing List (http://www.php.net/)
> >>>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>>
> >>>>
> >>>
> >>> --
> >>> <2866791487_dbbbdddf9e.jpg>惠 新宸 xinchen.hui | 商务搜索部 |
> (+8610)82602112-7974 | <2866349865_203e53a6c6.jpg>:laruence
> >>
> >>
> >
> > Do you have ANY errors/warning/notices?
> >
> >
> >
> > --
> > -----
> > Richard Quadling
> > "Standing on the shoulders of some very clever giants!"
> > EE : http://www.experts-exchange.com/M_248814.html
> > Zend Certified Engineer :
> http://zend.com/zce.php?c=ZEND002498&r=213474731
> > ZOPA : http://uk.zopa.com/member/RQuadling
>
>
--- End Message ---
--- Begin Message ---
OK you used ini_get try using ini_set and set the temporary directory on
your server of your choice at run time in your script (top of the script or
any config file if you have one).
REMEMBER that you have access to that directory, should have full
permissions and also check the absolute server path is correct while you set
the directory.
More information on how to use ini_set to set the directory path- try
googling...
Gaurav Kumar
blog.oswebstudio.com
On Fri, Dec 11, 2009 at 10:59 AM, kranthi <[email protected]> wrote:
> How can i change the temporary upload directory?
> var_dump(ini_get('upload_tmp_dir')); gives me (and that is set in
> php.ini)
> string '/var/www/cgi-bin' (length=16)
>
> but
> var_dump($_FILES) gives
> me
> 'tmp_name' => string '/tmp/phpbSZ6WP' (length=14)
>
> var_dump(file_exists($_FILES['file']['tmp_name'])); gives me (/tmp
> has permissions drwxrwxrwt and i never used file_move_upload or any
> similar functions)
> boolean false
>
> am I missing something here?
> Kranthi.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
i doubt i can use ini_set in this scenario
http://us3.php.net/manual/en/ini.core.php#ini.upload-tmp-dir
--- End Message ---
--- Begin Message ---
my mistake.... didn't use move_uploaded_file to see if the uploading
is working or not in the first case....
but i could not understand why
1. ini_get() is giving correct value while
$_FILES['file']['tmp_name'] is ignoring that.
2. move_uploaded_file($_FILES['file']['tmp_name'], 'file.php'); is
working fine but file_exists($_FILES['file']['tmp_name']) is returning
false
3. php_admin_value upload_tmp_dir "/var/www/html"
in httpd.conf seems to work ($_FILES['file']['tmp_name'] is not ignoring that);
--- End Message ---
--- Begin Message ---
2009/12/11 kranthi <[email protected]>:
> How can i change the temporary upload directory?
> var_dump(ini_get('upload_tmp_dir')); gives me (and that is set in
> php.ini)
> string '/var/www/cgi-bin' (length=16)
>
> but
> var_dump($_FILES) gives me
> 'tmp_name' => string '/tmp/phpbSZ6WP' (length=14)
>
> var_dump(file_exists($_FILES['file']['tmp_name'])); gives me (/tmp
> has permissions drwxrwxrwt and i never used file_move_upload or any
> similar functions)
> boolean false
>
> am I missing something here?
> Kranthi.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Just assuming you could alter the upload_tmp_dir setting in your code
(you can't) ...
PHP puts the uploaded files into the upload_tmp_dir BEFORE your script
runs, so changing it in your script essentially hides the uploaded
files.
PHP drops the files into directory A.
PHP then runs your code.
Your code changes the directory to B.
Your code cannot see the files PHP put into A as your code is now looking in B.
But, as I said earlier, you can't use your code to change
upload_tmp_dir. It can only be done at the system level (php.ini or
httpd.conf). See [1] and [2].
Regards,
Richard Quadling.
[1] http://docs.php.net/manual/en/ini.core.php#ini.sect.file-uploads
[2] http://docs.php.net/manual/en/configuration.changes.modes.php
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--- End Message ---
--- Begin Message ---
On Fri, 2009-12-11 at 15:44 +0000, Richard Quadling wrote:
> 2009/12/11 kranthi <[email protected]>:
> > How can i change the temporary upload directory?
> > var_dump(ini_get('upload_tmp_dir')); gives me (and that is set in
> > php.ini)
> > string '/var/www/cgi-bin' (length=16)
> >
> > but
> > var_dump($_FILES) gives
> > me
> > 'tmp_name' => string '/tmp/phpbSZ6WP' (length=14)
> >
> > var_dump(file_exists($_FILES['file']['tmp_name'])); gives me (/tmp
> > has permissions drwxrwxrwt and i never used file_move_upload or any
> > similar functions)
> > boolean false
> >
> > am I missing something here?
> > Kranthi.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> Just assuming you could alter the upload_tmp_dir setting in your code
> (you can't) ...
>
> PHP puts the uploaded files into the upload_tmp_dir BEFORE your script
> runs, so changing it in your script essentially hides the uploaded
> files.
>
> PHP drops the files into directory A.
> PHP then runs your code.
> Your code changes the directory to B.
> Your code cannot see the files PHP put into A as your code is now looking in
> B.
>
> But, as I said earlier, you can't use your code to change
> upload_tmp_dir. It can only be done at the system level (php.ini or
> httpd.conf). See [1] and [2].
>
> Regards,
>
> Richard Quadling.
>
> [1] http://docs.php.net/manual/en/ini.core.php#ini.sect.file-uploads
> [2] http://docs.php.net/manual/en/configuration.changes.modes.php
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>
The only reason I can see for wanting to do this would be where several
sites exist on the same server and you might want each site to have its
own temporary upload directory. It won't have any bearing on how you
handle the uploads unless it becomes full.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Thu, 2009-12-10 at 16:25 +0000, Ashley Sheridan wrote:
> On Thu, 2009-12-10 at 11:25 -0500, Robert Cummings wrote:
>
> > Joseph Thayne wrote:
> > > If the site can be a few minutes behind, (say 15-30 minutes), then what
> > > I recommend is to create a caching script that will update the necessary
> > > files if the md5 checksum has changed at all (or a specified time period
> > > has past). Then store those files locally, and run local copies of the
> > > files. Your performance will be much better than if you have to request
> > > the page from another server every time. You could run this script
> > > every 15-30 minutes depending on your needs via a cron job.
> >
> > Use URL rewriting or capture 404 errors to handle the proxy request. No
> > need to download and cache the entire site if everyone is just
> > requesting the homepage.
> >
> > Cheers,
> > Rob.
> > --
> > http://www.interjinn.com
> > Application and Templating Framework for PHP
> >
>
>
> Yeah, I was going to use the page request to trigger the caching
> mechanism, as it's unlikely that all pages are going to be equally as
> popular as one another. I'll let you all know how it goes on!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
Well I got it working just great in the end. Aside from the odd issue
with relative URLs use in referencing images and Javascripts that I had
to sort out, everything seems to be working fine and is live. I've got
it on a 12-hour refresh, as the site will probably not be changing very
often at all. Thanks for all the pointers!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Am I just drunk or blind or the documentation is simply wrong?
>From the official doc
(http://uk2.php.net/manual/en/function.move-uploaded-file.php):
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
The path for the upload dir should be a relative one, not an absolute one.
Roberto Aloi
http://aloiroberto.wordpress.com
Twitter: @prof3ta
--- End Message ---