Link to home
Start Free TrialLog in
Avatar of Oppital
OppitalFlag for Brazil

asked on

Secure upload with php

I need a php script that securely upload files larger than 10MB
Avatar of Oppital
Oppital
Flag of Brazil image

ASKER

I have this file, however, it makes less than 2 MB upload
<?
// Prepara a variável caso o formulário tenha sido postado
$arquivo = isset($_FILES["foto"]) ? $_FILES["foto"] : FALSE;

// nome da imagem
$imagem_nome = $_POST["nomejpg"];


$config["diretorio"] = "";


if($arquivo)
{
    $erro = array();
    

    if(!eregi("^image\/(pjpeg|jpeg|png|gif|bmp)$", $arquivo["type"]))
    {
        $erro[] = "Arquivo em formato inválido! A imagem deve ser jpg, jpeg, bmp, gif ou png. Envie outro arquivo";
    }
    else
    {


    }

    if(!sizeof($erro))
    {
        // Pega extensão do arquivo, o indice 1 do array conterá a extensão
        preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $arquivo["name"], $ext);
        

        // Caminho de onde a imagem ficará
        $imagem_dir = $config["diretorio"] . $imagem_nome;

        // Faz o upload da imagem
        move_uploaded_file($arquivo["tmp_name"], $imagem_dir);
    }
}
?>
<html>
<head>
<title>Enviar Foto</title>
<style type="text/css">
BODY, TD {font-family: verdana; font-size: 10pt; color: white}
</style>
</head>

<body bgcolor=black link=red vlink=red alink=red>

<center><font size=4>Envio de Foto</font><BR>
<?
// Imagem foi enviada com sucesso, mostra mensagem de SUCESSO
if($arquivo && !sizeof($erro))
{
  echo  "<BR><BR>Sua foto foi enviada com sucesso!<br>";
}

// Ocorreu algum erro ou ainda o formulário não foi postado
else
{
?>
<form action="<?echo $PHP_SELF?>" method=post  ENCTYPE="multipart/form-data">
<table border=0 cellpadding=2 cellspacing=1 align=center>
<?
if(sizeof($erro))
{
    echo "<tr><td colspan=2 bgcolor=red><B><U>Ocorreu(am) o(s) seguinte(s) erro(s):</u><BR>";
    foreach($erro as $err)
    {
        echo " - " . $err . "<BR>";
    }
    echo "</B></td></tr>";
}
?>
<tr><td align=center>Enviar Foto: <input value="C:\systeam\imgs\300x05-01-11.17.01.03.jpg" name="foto" type="file" ></td></tr>
<tr><td align=center>nomejpg: <input name="nomejpg" value="300x05-01-11.17.01.03.jpg" />    </td></tr>
<tr><td align=center><input name=botao id=botao type=submit value="Ok!"></td></tr>
</table>
</form>
<? } ?>
</body>
</html>

Open in new window

You can put any upload script behind HTTPS and it will be a "secure" upload.  The size of the files you can upload are controlled by PHP settings and by settings in the form.  Check these man page references:
http://php.net/manual/en/features.file-upload.php
http://php.net/manual/en/features.file-upload.common-pitfalls.php
http://php.net/manual/en/function.move-uploaded-file.php
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi
You can use amazon s3 to upload files straight to the s3 and it will have optiion of https the first gig is free considering you have smaller files to process
Avatar of Oppital

ASKER

Actually solved the problem
Thanks for the points -- it's a great question and the answers are not easy to find all in one place.  Best regards, ~Ray
Thanks Ray - I needed this solution on the same website you were helping me with & it works like a champ !