How to create upload files without using "input file"?

Asked

Viewed 1,101 times

-1

How do I upload files without including input file, that is, only using textField in HTML?

I managed to solve staff follows below the solution

<?php 
$numtotal=5;
$erro;

for($i=0;$i<$numtotal;$i++){
    $arquivo=$_POST['arquivo'][$i];
    $format=str_replace(".txt","",$arquivo);
    $tipoArq=substr($arquivo,-4);
    $arquivoinvert=strrev($arquivo);
    $arquivoinvert=strstr($arquivoinvert,"/",true);
    $arquivoinvert=strrev($arquivoinvert);

    if($tipoArq==".txt"){

            $arquivoinvert=str_replace(".txt","",$arquivoinvert);
            $formatadata=date("d-m-Y-h-i-s");
            $formatdata=str_replace("-","",$formatadata);       
            $caminho="/opt/lampp/htdocs/upload/uploads/".$arquivoinvert.$formatdata.$tipoArq;
            copy($arquivo,$caminho);
            include ("banco.php");

            echo $arquivo.'<br/>';

    }

    else{
        $erro="A extensão do arquivo não é valida";
        echo $erro;
    }
}



?>
  • 2

    What do you mean? want to save only the path and not the content?

  • 1

    You want to without input? Would not be input occult? See this example: http://jsfiddle.net/u4W8G/

  • There is a jQuery Dropzone plugin that can solve your problem: http://www.dropzonejs.com/

  • I don’t need more @Silenobrito, thank you for the suggestion, I did it in the nail using the textfield ;)

  • 6

    Please publish your solution as an Answer. And check out editing help.

2 answers

1

I managed to solve staff follows below the solution

<?php 
$numtotal=5;
$erro;

for($i=0;$i<$numtotal;$i++){
    $arquivo=$_POST['arquivo'][$i];
    $format=str_replace(".txt","",$arquivo);
    $tipoArq=substr($arquivo,-4);
    $arquivoinvert=strrev($arquivo);
    $arquivoinvert=strstr($arquivoinvert,"/",true);
    $arquivoinvert=strrev($arquivoinvert);

    if($tipoArq==".txt"){

            $arquivoinvert=str_replace(".txt","",$arquivoinvert);
            $formatadata=date("d-m-Y-h-i-s");
            $formatdata=str_replace("-","",$formatadata);        
            $caminho="/opt/lampp/htdocs/upload/uploads/".$arquivoinvert.$formatdata.$tipoArq;
            copy($arquivo,$caminho);
            include ("banco.php");

            echo $arquivo.'<br/>';

    }

    else{
        $erro="A extensão do arquivo não é valida";
        echo $erro;
    }
}



?>

0

If your idea is to pass the url of some image through the textField field you can do as follows:

<?php
    $url = "http://...."; //url da imagem que venha de um textField

    //PEGA INFORMAÇÕES DA IMAGEM
    $file_info = getimagesize($url);


    //VERIFICA EXTENSÃO DA IMAGEM
    if ($file_info['mime'] == "image/jpeg")
        $img = imagecreatefromjpeg($url);
    else if ($file_info['mime'] == "image/gif")
        $img = imagecreatefromgif($url);
    else if ($file_info['mime'] == "image/png")
        $img = imagecreatefrompng($url);

    $altura = $file_info[1];

    //PASSA AS MEDIDAS PARA A IMAGEM
    $x   = imagesx($img);
    $y   = imagesy($img);
    $largura = ($altura * $x)/$y;


    //CRIA A IMAGEM
    $nova = imagecreatetruecolor($largura, $altura);
    imagealphablending( $nova, false );
    imagesavealpha( $nova, true );
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);


    //NOME DA IMAGEM
    $imgName = end(explode("/", $url));

    //LOCAL PARA SALVAR
    $pasta = "."; // defina sua path
    $local = $pasta . $imgName;


    //SALVA NOVA IMAGEM
    if ($file_info['mime'] == "image/jpeg")
        imagejpeg($nova, $local, 100);
    else if ($file_info['mime'] == "image/png")
        imagepng($nova, $local, 9);

    //DESTROI ELEMENTOS
    imagedestroy($img);
    imagedestroy($nova);
?>
  • thanks for the post William but tell me something I need to do with files, and not images... has some example???

Browser other questions tagged

You are not signed in. Login or sign up in order to post.