Newsgroup: it.comp.www.php
Titolo: upload di files: problema molto strano

Uso questo script per caricare files sul mio server, è sempre funzionato,
oggi è impazzito
questa è la prima pagina, col form.
<html>
<head>
<title>Upload di un file</title>
</head>
<body>
<h1>Upload di un file</h1>
<form enctype="multipart/form-data" method="post" action="do_upload.php">
<p><strong>File da trasferire:</strong><br>
<input type="file" name="img1" size="30"></p>
<P><input type="submit" name="submit" value="Upload File"></p>
</form>
</body>
</html>
da qui si esegue l'upload del file
<?
if ($img1_name != "") {
copy("$img1", "/home/httpd/vhosts/
alientech.it/httpdocs/upload/$img1_name
")
or die("Impossibile copiare il file!");
} else {
die("File non specificato");
}
?>
<html>
<head>
<title>File uploadato con successo!</title>
<body>
<h1>File uploadato con successo</h1>
<P>Hai inviato il file: <? echo "$img1_name"; ?>, di <? echo "$img1_size";
?>
bytes di tipo <? echo "$img1_type"; ?>.</p>
</body>
</html>
Faccio un esempio: creo un file .txt e ci metto dentro tante volte la parola
"ciao", ottengo un file di 7.502 byte, lo carico, ottengo sul server un file
di 14.802 byte !! inoltre nelle righe iniali del file caricato si trovano
queste "cose"
ciao ciao ciao  cia-----------------------------7d43291f10186
Content-Disposition: form-data; name="img1"; filename="C:\ciao.txt"
Content-Type: text/plain
invece il file che ho caricato io è del tipo
ciao ciao ciao  ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao
ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao
ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao
ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao ciao
provo a caricare un'immagine: l'immagine caricata diventa tutta "storta",
con artefatti di varia natura!!
Come mai???
grazie
Andrea

 funzionato, oggi h impazzito
Ti suggerisco di leggerti 
http://www.php.net/manual/en/features.file-upload.php
 per capire a
fondo quali sono le funzioni da usare per gestire l'upload. Ad esempio
la funzione copy andrebbe sostituita con move_uploaded_file e dovresti
anche inserire un controllo di sicurezza utilizzando is_uploaded_file.
Inoltre e' meglio utilizzare gli array superglobali $_GET e $_POST se
vuoi avere del codice portabile anche su sistemi con register_globals =
off.
Rif.
http://www.php.net/manual/en/language.variables.external.php
http://www.php.net/register_globals
-- 
I am what I am, I do what I can
Cerchi un programmatore PHP/MySQL? 
http://url.repository.biz/go/1Y
L'uomo, conscio di sbagliare, persevera.

> Ti suggerisco di leggerti
ok, di certo seguirņ il tuo consiglio, ma in locale lo script funziona senza
problemi!
grazie
Andrea

> Ti suggerisco di leggerti
ho modificato lo script, solo il pezzo che fa l'upload:
$uploaddir = 'dir';
$uploadfile = $uploaddir . $_FILES['img1']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile)) {
   print "File is valid, and was successfully uploaded. ";
   print "Here's some more debugging info:\n";
   print_r($_FILES);
} else {
   print "Possible file upload attack!  Here's some debugging info:\n";
   print_r($_FILES);
}
print "</pre>";
solo che continua a non funzionare!!
Ecco un esempio: immagine originale
http://www.alientech.it/banners/eurochibi_120x600_0.gif
immagine caricata:
http://www.alientech.it/upload/eurochibi_120x600_0.gif
come mai?
grazie
Andrea

 funziona senza problemi!
Stai pur certo che al momento della pubblicazione il tuo script non
avrebbe funzionato se sul server di destinazione e' abilitato safe_mode
= on o register_globals = off.


 solo che continua a non funzionare!!
Ovvio, per verifica stai guardando l'immagine sbagliata!!!!
Il codice:
$uploaddir = 'dir';
$uploadfile = $uploaddir . $_FILES['img1']['name'];
Fa in modo che il file venga salvato in "dir$_FILES['img1']['name']" e
non "dir/$_FILES['img1']['name']".
Sostituisci con:
$uploadfile = $uploaddir . "/" . $_FILES['img1']['name'];


> Sostituisci con:
hai ragione, solo che continua a non funzionare:
immagine originale:
http://www.alientech.it/banners/eurochibi_120x600_0.gif
immagine caricata:
http://www.alientech.it/upload/eurochibi_120x600_0.gif
Andrea

faccio anche un'altra prova: carico il file fede_piccolo.txt
che contiene questo testo
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
e sul server ottengo questo file (č circa il doppio del file originale e
viene aggiunto il pezzo
-----------------------------7d4195179061-----------------------------7d4195
1790612
Content-Disposition: form-data; name="img1"; filename="C:\fede_grande.txt"
Content-Type: text/plain)
questo fede_grande sul server:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-----------------------------7d4195179061-----------------------------7d4195
1790612
Content-Disposition: form-data; name="img1"; filename="C:\fede_grande.txt"
Content-Type: text/plain
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
come mai tutto questo?

 faccio anche un'altra prova: carico il file fede_piccolo.txt
...
Segue codice perfettamente funzionante:
<html>
<head>
<title>Upload di un file</title>
</head>
<body>
<h1>Upload di un file</h1>
<form enctype="multipart/form-data" method="post">
  <p><strong>File da trasferire:</strong><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <input type="file" name="img1" size="30">
  </p>
  <p> 
    <input type="submit" name="submit" value="Upload File">
  </p>
</form>
</body>
</html>
<?php
if (isset ($_POST["submit"]))
{
	$uploaddir = 'dir';
	$uploadfile = $uploaddir . "/" . $_FILES['img1']['name'];
 
	print "<pre>";
	if (move_uploaded_file ($_FILES['img1']['tmp_name'], $uploadfile)) {
	   print "File is valid, and was successfully uploaded. ";
	   print "Here's some more debugging info:\n";
	   print_r($_FILES);
	} else {
	   print "Possible file upload attack!  Here's some debugging info:\n";
	   print_r($_FILES);
	}
	print "</pre>";
	?>
<html>
<head>
<title>File uploadato con successo!</title>
</head>
<body>
<h1>File uploadato con successo</h1>
<p>Hai inviato il file: <?php echo $_FILES["img1"]["name"]; ?>, di
<?php echo $_FILES["img1"]["size"]; ?>
  bytes di tipo <?php echo $_FILES["img1"]["type"]; ?>.</p>
</body>
</html>
<?php 
} 
?>


> Segue codice perfettamente funzionante:
scusa ma apparte il fatto che io uso due pagine: una con il form ed una per
caricare il file, dov'è la differenza :ooo ?
grazie
Andrea
pagina col form
<html>
<head>
<title>Upload di un file</title>
</head>
<body>
<h1>Upload di un file</h1>
<form enctype="multipart/form-data" method="post" action="do_upload1.php">
<p><strong>File da trasferire:</strong><br>
<input type="file" name="img1" size="30"></p>
<P><input type="submit" name="submit" value="Upload File"></p>
</form>
</body>
</html>
pagina per fare l'upload:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
instead
// of $_FILES.
$uploaddir = '/home/httpd/vhosts/
alientech.it/httpdocs/upload
';
$uploadfile = $uploaddir . "/" . $_FILES['img1']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile)) {
   print "File is valid, and was successfully uploaded. ";
   print "Here's some more debugging info:\n";
   print_r($_FILES);
} else {
   print "Possible file upload attack!  Here's some debugging info:\n";
   print_r($_FILES);
}
print "</pre>";
?>
</body>
</html>

 una per caricare il file, dov'h la differenza :ooo ?
Che il codice che ho postato funziona?


> Che il codice che ho postato funziona?
sě, ma io voglio capire perchč il tuo funziona ed il mio no: non vedo
nessuna differenza apparte il fatto che io uso due pagine e tu una.
Tal'altro, il mio in locale funziona, quando lo carico sul server no
grazie

 Tal'altro, il mio in locale funziona, quando lo carico sul server no
[mi quoto]
Stai pur certo che al momento della pubblicazione il tuo script non
avrebbe funzionato se sul server di destinazione e' abilitato safe_mode
= on o register_globals = off.
[/quoto]
Controlla bene la form, c'e' qualche cosa di significativamente
diverso..


 diverso..
l'unica differenza credo che sia
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
quindi ho reso la form come a fine post, ma il risultato resta sempre lo
stesso: immagini alterate nell'aspetto e files di testo alterati nel
contenuto.... la cosa mi lascia molto perplesso...
Andrea
<html>
<head>
<title>Upload di un file</title>
</head>
<body>
<h1>Upload di un file</h1>
<form enctype="multipart/form-data" method="post" action="do_upload1.php">
  <p><strong>File da trasferire:</strong><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
    <input type="file" name="img1" size="30">
  </p>
  <p>


ho risolto: è un bug associato a
php 4.2.3 + apache 2.0
l'hoster ha risolto mettendo
#<Files *.php>
#    SetOutputFilter PHP
#    SetInputFilter PHP
#    LimitRequestBody 524288
#</Files>
Andrea

scusate se mi intrometto anch'io, ma è da un po' che cerco di fare una
pagine per fare l'upload di file sul server, ma non ci riesco! Ho provato il
codice scritto da Setec Astronomy, ma non mi funziona. Ecco quello che mi
stampa:
Possible file upload attack!  Here's some debugging info:
Array
(
    [up_file] => Array
        (
            [name] => enigmi.txt
            [type] => text/plain
            [tmp_name] => C:\PHP\uploadtemp\php68E0.tmp
            [error] => 0
            [size] => 7466
        )
)
perchè non va??? è possibile che ci sia qualche settaggio nella config di
PHP che mi impedisce gli upload?

 PHP che mi impedisce gli upload?
hai impostato il chmod della directory nella quale vuoi caricare il file?

non me lo fa fare! mi da errore... si fa con il comando chmod($directory,
$attribs)? Come attributi ho messo 0777, cosě tutti possono leggere,
scrivere ed eseguire, ma non me lo fa fare!
Continua a non funzionare...