Foros del Web » Programando para Internet » PHP »

Ayuda para convertir funcion

Estas en el tema de Ayuda para convertir funcion en el foro de PHP en Foros del Web. Estuve usando un script que creo que usa esta funcion allow_url_fopen pero mi hosting (Dremahost) no lo admite pero lei que se puede cambiar por ...
  #1 (permalink)  
Antiguo 31/01/2008, 10:03
michi122513
Invitado
 
Mensajes: n/a
Puntos:
Ayuda para convertir funcion

Estuve usando un script que creo que usa esta funcion allow_url_fopen pero mi hosting (Dremahost) no lo admite pero lei que se puede cambiar por la funcion curl, creo que por aqui esta el problema:

Código PHP:
    function url_upload(){
        global 
$CONFIG$DB$UDATA$file_count$path$filename;
        for(
$i 0$i <= 15$i++){
            
$file = array(
                
'name'  => array_shift(explode('?'basename($_POST['userfile'][$i]))),
                
'url'   => $_POST['userfile'][$i],
                
'rand'  => random_string(20)
            );
            if(
$file['name'] != ''){
                
$file_count++;
                if(
$file_count <= 15){
                    if(
$i >= 1){
                        echo 
"<div class='cell_divider'></div><br>\n";
                    }
                    
$extension file_type($file['name']);
                    
$filename  $file['rand'].".".$extension;
                    
$thumbnail thumbnail_name($filename);
                    if(!
preg_match("/(https|http|ftp):\/\/[^\"\s']+/"$file['url'])){
                        
message("The file <b>{$file['name']}</b> contains a invalid URL.");
                    }elseif(!
in_array($extension$CONFIG['file_types'])){
                        
message("The file <b>{$file['name']}</b> extension is not allowed.");
                    }elseif(!
$fcc implode(''file($file['url']))){
                        
message("The file <b>{$file['name']}</b> is not readable or does not exists.");
                    }elseif(
strlen($fcc) > $CONFIG['max_file_size']){
                        
message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
                    }elseif(
strlen($fcc) < 5){
                        
message("The file <b>{$file}</b> contains no data.");
                    }elseif(
file_exists(ROOT_PATH.$path.$filename) !== false){
                        
message("The file <b>{$file['name']}</b> seems to already exists on this server.");
                    }elseif(!
fwrite(fopen($path.$filename'x'), $fcc)){
                        
message("File transfer failed for file <b>{$file['name']}</b>.");
                    }else{
                        if(
$CONFIG['is_user'] == true){
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
                        }else{
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
                        }
                        
$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
                        
create_thumbnail($filename);
                        
results_table();
                    }
                }
            }
        }
    } 
  #2 (permalink)  
Antiguo 31/01/2008, 10:13
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Ayuda para convertir funcion

En ese código que publicas no veo ninguna llamada a fopen o alguna función similar que use la directiva allow_url_fopen.

Saludos.
  #3 (permalink)  
Antiguo 31/01/2008, 10:19
michi122513
Invitado
 
Mensajes: n/a
Puntos:
Re: Ayuda para convertir funcion

aqui hay un pedazo que me parecio que era no se si estoy bien ya que no se mucho de php


Código PHP:
                    }elseif(!fwrite(fopen($path.$filename'x'), $fcc)){
                        
message("File transfer failed for file <b>{$file['name']}</b>."); 
GRacias por tu ayuda
  #4 (permalink)  
Antiguo 31/01/2008, 10:26
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Ayuda para convertir funcion

Esa parte es para escribir en un archivo, tuvieras o no activado allow_url_fopen, no vas a poder usar fwrite para escribir en un URL, tienes que usar un WebService para eso.

Saludos.
  #5 (permalink)  
Antiguo 31/01/2008, 10:51
michi122513
Invitado
 
Mensajes: n/a
Puntos:
Re: Ayuda para convertir funcion

que es webservice? mi problema es que el script que uso (http://www.mihalism.com/product/mmh/download/) tiene una funcion que sirve para subir imagenes desde una url pero me bota error cuando intento subir : is not readable or does not exists.

cual puede ser el problema...por lo que lei tiene que ver algo con curl.

Y una pregunta más quiero aprender php pero en localhost solo para practicar que debo descargar para empezar :S
  #6 (permalink)  
Antiguo 31/01/2008, 10:59
michi122513
Invitado
 
Mensajes: n/a
Puntos:
Re: Ayuda para convertir funcion

Problema solucionado, contacte con un usuario del script y me dio la solucion:

Código PHP:
<?php
    
/*
    *
    * Mihalism multi host v3.1.x                      
    * Copyright (c) 2005 - 2007 Mihalism Inc (www.mihalism.com)
    *
    */
    
require_once('./page_header.php');

    
$file_count 0;
    
$path       $CONFIG['file_path'];

    switch(
$_POST['type']){
        case 
'url_upload':
            
url_upload();
            break;
        default:
            
direct_upload();
    }

    function 
url_upload(){
        global 
$CONFIG$DB$UDATA$file_count$path$filename;
        for(
$i 0$i <= 15$i++){
            
$file = array(
                
'name'  => $_POST['userfile'][$i],
                
//'name'  => array_shift(explode('?', basename($_POST['userfile'][$i]))),
                
'url'   => $_POST['userfile'][$i],
                
'rand'  => random_string(20)
            );
            if(
$file['name'] != ''){
                
$file_count++;
                if(
$file_count <= 15){
                    if(
$i >= 1){
                        echo 
"<div class='cell_divider'></div><br>\n";
                    }
                    
//var_dump($_POST['userfile'][$i] );
                    
$extension file_type($file['name']);
                    
$filename  $file['rand'].".".$extension;
                    
$thumbnail thumbnail_name($filename);
                    if(!
preg_match("/(https|http|ftp):\/\/[^\"\s']+/"$file['url'])){
                        
message("The file <b>{$file['name']}</b> contains a invalid URL.");
                    }elseif(!
in_array($extension$CONFIG['file_types'])){
                        
message("The file <b>{$file['name']}</b> extension is not allowed.");
                    }elseif(!
$fcc cupload($file['name'])){
                        
message("The file <b>{$file['name']}</b> is not readable or does not exists.");
                    }elseif(
strlen($fcc) > $CONFIG['max_file_size']){
                        
message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
                    }elseif(
strlen($fcc) < 500){
                        
message("The file <b>{$file}</b> contains no data.");
                    }elseif(
file_exists(ROOT_PATH.$path.$filename) !== false){
                        
message("The file <b>{$file['name']}</b> seems to already exists on this server.");
                    }elseif(!
fwrite(fopen($path.$filename'x'), $fcc)){
                        
message("File transfer failed for file <b>{$file['name']}</b>.");
                    }else{
                        if(
$CONFIG['is_user'] == true){
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
                        }else{
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
                        }
                        
$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
                        
create_thumbnail($filename);
                        
results_table();
                    }
                }
            }
        }
    }

    function 
cupload($image_url){
        
$ch curl_init();
        
$timeout 0;
        
curl_setopt ($chCURLOPT_URL$image_url);
        
curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout);

        
// Getting binary data
        
curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
curl_setopt($chCURLOPT_BINARYTRANSFER1);

        
$image curl_exec($ch);
        
curl_close($ch);

        return 
$image;
    }

    function 
direct_upload(){
        global 
$CONFIG$DB$UDATA$file_count$path$filename;
        for(
$i 0$i <= 15$i++){
            
$file = array(
                
'name'  => $_FILES['userfile']['name'][$i],
                
'size'  => $_FILES['userfile']['size'][$i],
                
'tmp'   => $_FILES['userfile']['tmp_name'][$i],
                
'error' => $_FILES['userfile']['error'][$i],
                
'rand'  => random_string(20)
            );
            if(
$file['error'] != && $file['name'] != ''){
                
$file_count++;
                if(
$file_count <= 15){
                    if(
$i >= 1){
                        echo 
"<div class='cell_divider'></div><br>\n";
                    }
                    
$extension file_type($file['name']);
                    
$filename  $file['rand'].".".$extension;
                    
$thumbnail thumbnail_name($filename);
                    if(!
in_array($extension$CONFIG['file_types'])){
                        
message("The file {$file['name']}</b> extension is not allowed.");
                    }elseif(
$file['size'] > $CONFIG['max_file_size']){
                        
message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
                    }elseif(
$file['error'] != 0){
                        
$filerror = array(            
                            
=> "The file <b>{$file['name']}</b> exceeds the <a href=\"http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize\">upload_max_filesize</a> directive in php.ini.",
                            
=> "The file <b>{$file['name']}</b> exceeds the <b><i>MAX_FILE_SIZE</i></b> directive that was specified in the HTML form.",
                            
=> "The file <b>{$file['name']}</b> was only partially uploaded.",
                            
=> "Missing a temporary folder.",
                            
=> "Failed to write file <b>{$file['name']}</b> to disk.",
                            
=> "File <b>{$file['name']}</b> upload stopped by extension."
                                
);
                        
message($filerror[$file['error']]);
                    }elseif(
file_exists(ROOT_PATH.$path.$filename)){
                        
message("The file <b>{$file['name']}</b> seems to already exists on this server.");
                    }elseif(!
move_uploaded_file($file['tmp'], ROOT_PATH.$path.$filename)){
                        
message("File upload failed for file <b>{$file['name']}</b>.");
                    }else{
                        if(
$CONFIG['is_user'] == true){
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
                        }else{
                            
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
                        }
                        
$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
                        
create_thumbnail($filename);
                        
results_table();
                    }
                }
            }
        }
    }

    if(
$file_count == 0){
        
message("Please go back and ".(($_POST['type'] != 'url_upload') ? 'select' 'enter')." at least one file to upload.");
    }

    require_once(
'./page_footer.php');
?>
Muchas gracias por toda la ayuda GatorV
PD: disculpen por el doble post
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:54.