---
title: "Errores en tratamiento de ficheros en PHP"
date: 2011-02-15
author: "Alex Borrás"
source: https://alexborras.com/errores-en-tratamiento-de-ficheros-en-php/
site: "El Blog de Alex Borrás"
---

# Errores en tratamiento de ficheros en PHP

Algunos servidores tienen desactivadas determinadas opciones de manejo de ficheros en PHP. Al utilizar funciones como fopen o file\_get\_contents se producen distintos mensajes de error.

Por ejemplo con fopen da el warning: «URL file-access is disabled in the server configuration«.

Para solucionar este problema podemos utilizar diversas funciones.

## Warning: file\_get\_contents()

\[PHP\]  

$contents = file\_get\_contents(‘http://www.cnn.com/’);  

echo $contents;  

\[/PHP\]  

\[PHP\]  

$ch = curl\_init();  

curl\_setopt ($ch, CURLOPT\_URL, ‘http://www.cnn.com’);  

curl\_setopt ($ch, CURLOPT\_RETURNTRANSFER, 1);  

$contents = curl\_exec($ch);  

curl\_close($ch);  

// display file  

echo $contents;  

\[/PHP\]

## Warning: getimagesize()

\[PHP\]  

$filename = “http://www.example.com/example.jpg”;  

$ch = curl\_init();  

curl\_setopt ($ch, CURLOPT\_URL, $filename);  

curl\_setopt ($ch, CURLOPT\_RETURNTRANSFER, 1);  

$contents = curl\_exec($ch);  

curl\_close($ch);  

$new\_image = ImageCreateFromString($contents);  

imagejpeg($new\_image, “temp.jpg”,100);  

$size = getimagesize(“temp.jpg”);  

// width and height  

$width = $size\[0\];  

$height = $size\[1\];  

\[/PHP\]

Artículo completo
