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
DuffMAn
Forum Newbie
Posts: 17 Joined: Thu Apr 03, 2003 4:53 pm
Post
by DuffMAn » Sun Apr 27, 2003 2:24 pm
I was trying to upload a file and php show me this.
Parse error: parse error, unexpected T_STRING in C:\Php Ide\nusphere\PHPEd\Foro 2.0\up.php on line 6
This is the code:
up.php
Code: Select all
<?php
if (! is_uploaded_file($userfile))
{
unlink($userfile);
$error = "Nada";
} // Line 6 --> Error???????????
else {
//a file was uploaded
$maxfilesize=10240;
if ($userfile_size > $maxfilesize) {
$error = "file is too large";
unlink($userfile);
// assign error message, remove uploaded file, redisplay form.
} else {
if ($userfile_type != "image/gif" AND $userfile_type != "image/pjpeg") {
$error = "This file type is not allowed";
unlink($userfile);
// assign error message, remove uploaded file, redisplay form.
} else {
//File has passed all validation, copy it to the final destination and remove the temporary file:
@ move_uploaded_file($userfile_type,"prueba/".$userfile_name);
unlink($userfile);
print "File has been successfully uploaded!";
exit;
}
}
}
?>
and the upload.html
Code: Select all
<html>
<form action="up.php" method="POST" enctype="multipart/form-data">
submit this file: <input type=file name="userfile"><br>
<input type=submit><br>
</form>
</html>
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Sun Apr 27, 2003 6:16 pm
Try eliminating the space between the exclamation mark and the variable:
Code: Select all
<?php
if (! is_uploaded_file($userfile))
?>
so it reads
Code: Select all
<?php
if (!is_uploaded_file($userfile))
?>
DuffMAn
Forum Newbie
Posts: 17 Joined: Thu Apr 03, 2003 4:53 pm
Post
by DuffMAn » Sun Apr 27, 2003 8:15 pm
I try it and give me the same error
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Sun Apr 27, 2003 9:03 pm
Instead of $userfile, try $_POST["userfile"]
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Sun Apr 27, 2003 11:38 pm
try
Code: Select all
<?php
if (!(is_uploaded_file($userfile)))
?>
and check phice post
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Apr 28, 2003 2:10 am
I tried running your code and didn't get any parse errors - did you copy and paste the script in?
Mac
DuffMAn
Forum Newbie
Posts: 17 Joined: Thu Apr 03, 2003 4:53 pm
Post
by DuffMAn » Mon Apr 28, 2003 11:32 am
twigletmac wrote: I tried running your code and didn't get any parse errors - did you copy and paste the script in?
Mac
Yes, I copy and paste the code.
I run the code in PHPED and online and gave me the error. Where did you run the code?.
DuffMAn
Forum Newbie
Posts: 17 Joined: Thu Apr 03, 2003 4:53 pm
Post
by DuffMAn » Mon Apr 28, 2003 6:33 pm
I solved the problem, thx
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Tue Apr 29, 2003 6:29 pm
what was the problem!!?!?!?!?!?!?
DuffMAn
Forum Newbie
Posts: 17 Joined: Thu Apr 03, 2003 4:53 pm
Post
by DuffMAn » Tue Apr 29, 2003 7:07 pm
I don´t know exactly. I just rewrite the script. Here it is.
Code: Select all
if(!empty($userfile)) {
$maxfilesize=50000;
$tipo = $userfile_type;
$tam = $userfile_size;
$nombre = $userfile_name;
$copiado = FALSE;
$imagehw = GetImageSize($userfile);
$imagewidth = $imagehwї0];
$imageheight = $imagehwї1];
if (($tam <= $maxfilesize ) AND ($imageheight <= 100 ) AND ($imagewidth <= 100) AND (($tipo == "image/pjpeg") OR ($tipo == "image/gif") OR ($tipo == "image/jpeg") OR ($tipo == "image/bmp") ) ) {
$nombre_avatar = "avatares/$USER_NOMBRE $nombre";
@ move_uploaded_file($userfile,$nombre_avatar);
$sql_change = mysql_query("UPDATE usuarios SET avatar='$nombre_avatar' WHERE nombre='$USER_NOMBRE'");
$copiado = TRUE;