HELP needed uploading a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

HELP needed uploading a file

Post by lisawebs »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm using a very simple script to upload files,
see html and php below.

I dont get error msg but the file never gets to my server.
Can you help me on this?

Code: Select all

<html><body>
<form enctype="multipart/form-data" action="http://www.usa21.net/testupload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="80000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Enviar Arquivo">
</form>
</body></html>


<html><body>
<!--upload_temp_dir no php.ini ou TMPDIR-->
<?php
// Nas versões anteriores a 4.1.0, $HTTP_POST_FILES deve ser usado ao invés de $_FILES.
// Nas versões anteriores a 4.0.3, use copy() e is_uploaded_file() ao invés move_uploaded_file

$uploaddir = '/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];
print "<pre>";
if ($_FILES['userfile']['size'] > 80000)
    print "O arquivo é muito grande";
else if ($_FILES['userfile']['type'] != "image/jpg)
   print "OArquivo não é JPG"
else if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
    print "O arquivo é valido e foi carregado com sucesso. Aqui esta alguma informação:\n";
    print_r($_FILES);
} else {
    print "Possivel ataque de upload! Aqui esta alguma informação:\n";
    print_r($_FILES);
}
print "</pre>";
?>
<!--
$_FILES['userfile']['name']
O nome original do arquivo no computador do usuário. 

$_FILES['userfile']['type']
O tipo mime do arquivo, se o browser deu esta informação. Um exemplo pode ser "image/gif". 

$_FILES['userfile']['size']
O tamanho, em bytes, do arquivo. 

$_FILES['userfile']['tmp_name']
O nome temporário do arquivo, como foi guardado no servidor. 

$_FILES['userfile']['error']
-->
</body></html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

General Discussion is specifically not for programming questions. Moved to PHP Code.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Hey look at the Color change.

Code: Select all

else if ($_FILES['userfile']['type'] != "image/jpg)
would be

Code: Select all

else if ($_FILES['userfile']['type'] != "image/jpg")
Post Reply