Page 1 of 2
Odd Parse error
Posted: Sat Sep 06, 2003 6:05 pm
by evilmonkey
I apologize ahead of time for the dumbe question, but this clause seems to be giving me a parse error:
Code: Select all
$uploaddir='/home/vagonweb/public_html/donotask/pics/';
if ($_FILES['thepic']['type'] != "image/pjpeg" ) {
echo "the image must be a jpeg!";
}
else {
if (move_uploaded_file($_FILES['thepic']['tmp_name'], $uploaddir . $_FILES['thepic']['name']))
{
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ($_SESSION['username'], '$title', '$description', '$category', $_FILES['thepic']['name'])";
$result=mysql_query($sql,$db);
echo "The file was successfully uploaded!";
}
else
{
echo "Your file could not be copied.";
}
unlink($thepic);
The $sql line seems to be the culprit, but I can't figure out what's wrong. Quote mishap perhaps?
Thanks!
Posted: Sat Sep 06, 2003 6:18 pm
by m3rajk
two things you can do....one: change
Code: Select all
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ($_SESSION['username'], '$title', '$description', '$category', $_FILES['thepic']['name'])";
to
Code: Select all
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$_SESSION['username']', '$title', '$description', '$category', '$_FILES['thepic']['name']')";
two: add this after the result line
Code: Select all
$errno=$mysql_errno($db);$error=mysql_error($db);$debug="query: $sql<br />error number: $errno<br />error: $error"; echo $debug;
and see what that tells you. should le tyou see the exact problem
Posted: Sat Sep 06, 2003 6:22 pm
by evilmonkey
Thank you for the reply, unfortunatly, it does nothing. This is the code:
Code: Select all
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$_SESSION['username']', '$title', '$description', '$category', '$_FILES['thepic']['name']')";
$errno=mysql_errno($db);
$error=mysql_error($db);
$debug="query: $sql<br />error number: $errno<br />error: $error";
echo $debug;
$result=mysql_query($sql,$db);
And this is the error:
Code: Select all
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/vagonweb/public_html/donotask/submit.php on line 90
EDIT: I understan now. The code you gave me checks for MySQl errors. This spits out a PHP error before mysql is even reached.
Thanks!
Posted: Sat Sep 06, 2003 6:28 pm
by m3rajk
evilmonkey wrote:Thank you for the reply, EDIT: I understan now. The code you gave me checks for MySQl errors. This spits out a PHP error before mysql is even reached.
Thanks!
np. hehe. i nearly made the mistake of saying after that instead of after result because i do it a bit different, so i understand why you made that mistake., it's very logical
Posted: Sat Sep 06, 2003 6:28 pm
by evilmonkey
but the problem is, I still have the aforementioned PHP error.

Posted: Sat Sep 06, 2003 7:12 pm
by m3rajk
did you put in errno=$mysql_errno($db); or errno=mysql_errno($db); ? i ask because the $ will cause it
Posted: Sat Sep 06, 2003 7:15 pm
by evilmonkey
Nope, I got rid of $. But once again, line 90 is the line of the $sql"".
Posted: Sat Sep 06, 2003 7:15 pm
by m3rajk
nvmd. keep that incase you have a sql error. it'll help. i see the error.
you're using an arra element directly in the string. you have to put {} in a certain place or it will give errors. you can break it up ... try making......
Code: Select all
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ($_SESSION['username'], '$title', '$description', '$category', $_FILES['thepic']['name'])";
into
Code: Select all
$submitter=$_SESSION['username'];
$url=$_FILES['thepic']['name'];
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$submitter', '$title', '$description', '$category', '$url')";
Posted: Sat Sep 06, 2003 7:57 pm
by evilmonkey
Alright, that seems to have subdued that error, but i seem to have another one. Here's the code once again:
Code: Select all
$uploaddir='/home/vagonweb/public_html/donotask/pics/';
if ($_FILES['thepic']['type'] != "image/pjpeg") {
echo $_FILES['thepic']['type'];
echo "the image must be a jpeg!";
}
else {
if (move_uploaded_file($_FILES['thepic']['tmp_name'], $uploaddir . $_FILES['thepic']['name']))
{
$submitter=$_SESSION['username'];
$url=$_FILES['thepic']['name'];
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$submitter', '$title', '$description', '$category', '$url')";
$errno=mysql_errno($db);
$error=mysql_error($db);
$debug="query: $sql<br />error number: $errno<br />error: $error";
echo $debug;
$result=mysql_query($sql,$db);
echo "The file was successfully uploaded!";
The problem is, it always tells me that the image must be a jpeg when it really is. When i ask to echo the $_FILE['thepic']['type'], it comes out blank. What is the problem?
Thanks for your help.
Posted: Sun Sep 07, 2003 3:19 am
by JAM
About the old, now fixed, previous problem...
Code: Select all
VALUES ($_SESSIONї'username'],
should be
Code: Select all
VALUES ('$_SESSIONїusername]',
etc. etc.
Note the single quotes left out withinin the variable, and the quotes added around it.
What does print_r($_FILES) tell you?
Posted: Sun Sep 07, 2003 10:14 am
by evilmonkey
print_r($FILES) spits out:
Code: Select all
Array ( їthepic] => Array ( їname] => Winter.jpg їtype] => їtmp_name] => їerror] => 2 їsize] => 0
error=>2???
Posted: Sun Sep 07, 2003 12:22 pm
by volka
http://www.php.net/manual/en/features.file-upload.errors.phpUPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.
Posted: Sun Sep 07, 2003 1:19 pm
by m3rajk
evilmonkey wrote:Alright, that seems to have subdued that error, but i seem to have another one. Here's the code once again:
Code: Select all
$uploaddir='/home/vagonweb/public_html/donotask/pics/';
if ($_FILES['thepic']['type'] != "image/pjpeg") {
echo $_FILES['thepic']['type'];
echo "the image must be a jpeg!";
}
else {
if (move_uploaded_file($_FILES['thepic']['tmp_name'], $uploaddir . $_FILES['thepic']['name']))
{
$submitter=$_SESSION['username'];
$url=$_FILES['thepic']['name'];
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$submitter', '$title', '$description', '$category', '$url')";
$errno=mysql_errno($db);
$error=mysql_error($db);
$debug="query: $sql<br />error number: $errno<br />error: $error";
echo $debug;
$result=mysql_query($sql,$db);
echo "The file was successfully uploaded!";
The problem is, it always tells me that the image must be a jpeg when it really is. When i ask to echo the $_FILE['thepic']['type'], it comes out blank. What is the problem?
Thanks for your help.
i had that too. you see it's 1: guessed at by the user's browser
2: optional to do by the browser
to actually get it use
getImageSize
it returns an array, so you'd so something like
Code: Select all
$imageInfo=getImageSize($_FILES['thepic']['tmpname']);
now you can check height and width if you want. you see....
$imageInfo[0]==width in pixels
$imageInfo[1]==height in pixels
$imageInfo[2]==image type (check link for the numbers and equivalents. jpeg is 2)
$imageInfo[3]==string that can be placed into a img tag that gives the image's height and width
Posted: Sun Sep 07, 2003 1:27 pm
by pootergeist
a more useful way of running file upload returns..
Code: Select all
// amend form_field_name to suit the name you used.
$err_code = $_FILES['form_field_name']['error'];
$uplo_return_str = '';
if($err_code != 0)
{
// amend the [89,000] to suit the MAX_FILE_SIZE as set in the html
$uplo_return_str = ($err_code < 5) ? ($err_code < 4) ? ($err_code < 3) ? ($err_code < 2) ?
'Upload File was above ' .ini_get('upload_max_filesize'). ' bytes in size.<br />' :
'Upload File was above [ 89,000 ] bytes in size.<br />' :
'Upload File was only partially uploaded, please try again.<br />' :
'No Upload File received, please try again.<br />' :
'Unknown Error Encountered, please try uploading again.<br />' ;
}
else
{
// successful upload of something - do more tests - add rest of upload code
// once again amend form_field_name to suit the name you used.
$img_size = getimagesize($_FILES['form_field_name']['tmp_name']);
if($img_size[2] == 2)
{
// woot - a jpeg successfully uploaded
// we also now have $img_size[0] holding the width and $img_size[1] the height
move_uploaded_file($_FILES['form_field_name']['tmp_name'], 'somewhere/somename.jpg');
$uplo_return_str = 'w00t w00t - methinks that was successful.<br />';
}
else
{
$uplo_return_str = 'Now, that was a jpeg was it? - I think it wasn''t - wanna try again?<br />';
}
}
echo $uplo_return_str;
returns a bit more information - might be helpful for debugging. Also use getimagesize to pull the mime type rather than phps $_FILES[]['type'] method.
Posted: Sun Sep 07, 2003 7:18 pm
by evilmonkey
Hmm...the problem is still not fixed...
Code: Select all
if ($_SESSION['auth']===true)
{
if ($foo=="bar")
{
$err_code = $_FILES['thepic']['error'];
$uplo_return_str = '';
if($err_code != 0)
{
// amend the [89,000] to suit the MAX_FILE_SIZE as set in the html
$uplo_return_str = ($err_code < 5) ? ($err_code < 4) ? ($err_code < 3) ? ($err_code < 2) ?
$msg='Upload File was above ' .ini_get('upload_max_filesize'). ' bytes in size.<br />' :
$msg='Upload File was above [ 89,000 ] bytes in size.<br />' :
$msg='Upload File was only partially uploaded, please try again.<br />' :
$msg='No Upload File received, please try again.<br />' :
$msg='Unknown Error Encountered, please try uploading again.<br />' ;
echo $msg;
}
else
{
// successful upload of something - do more tests - add rest of upload code
// once again amend form_field_name to suit the name you used.
$img_size = getimagesize($_FILES['thepic']['tmp_name']);
if($img_size[2] == 2)
{
// woot - a jpeg successfully uploaded
// we also now have $img_size[0] holding the width and $img_size[1] the height
if (move_uploaded_file($_FILES['thepic']['tmp_name'], 'pics/'.$_FILES['thepic']['name']))
{
$submitter=$_SESSION['username'];
$url=$_FILES['thepic']['name'];
$sql="INSERT INTO pics (submitter, title, description, category, url) VALUES ('$submitter', '$title', '$description', '$category', '$url')";
$errno=mysql_errno($db);
$error=mysql_error($db);
$debug="query: $sql<br />error number: $errno<br />error: $error";
echo $debug;
$result=mysql_query($sql,$db);
echo "The file was successfully uploaded!";
}
else
{
echo "Your file could not be copied.";
}
unlink($thepic);
}
}
}
else
{
echo "<p align="center">";
echo "<form method="post" enctype="multipart/form-data" action="$PHP_SELF">";
echo "<input type="hidden" name="MAX_FILE_SIZE" value="10000000000">";
echo "Title:<br>";
echo "<input type="text" name="title" size="50"><br>";
echo "Description:<br>";
echo "<textarea name="description" cols="40" rows="7"></textarea><br>";
echo "File:<br>";
echo "<input type="file" name="thepic"><br>";
echo "Category:<br>";
echo "<select name="category">";
echo "<option value="pixel">Pixel</option>";
echo "<option value="photo">Photo</option>";
echo "<option value="photo_manip">Photo Manipulation </option>";
echo "<option value="sketch">Sketch</option>";
echo "<option value="digital">DigiArt</option>";
echo "<option value="3d">3D</option>";
echo "<option value="classic">Classic</option>";
echo "<option value="other">Other</option>";
echo "</select><br>";
echo "<input type="submit">";
echo "<input type="hidden" name="foo" value="bar">";
echo "</form>";
echo "</p>";
}
}
else
{
echo "Unathorized access";
}
?>
Now it tells me that the upload is too big. Notice the MAX_FILE_SIZE in the form, I theoretically shouldn't be having problems with a 100 kb jpg image...
Thanks for you help.