PLEASE help with my PHP issue

I am trying to create a form that allows visitors to my site to upload pictures to my database. I already have the form, the connect to db connection, and everything else. I just get this issue when I try to preview it in my

browser. “Parse error: syntax error, unexpected ‘;’ in /home/blah/public_html/blah.com/blah/upload.php on line 88”

----Issue is on line 88, 99, and 106.
----All this code is in one page, upload.php
----Line # are marked to the write of the code with a // <---- line #

The code:

[php]

<?php // if something was posted, start the process... if(isset($_POST['upload'])) { // define the posted file into variables $name = $_FILES['picture']['name']; $tmp_name = $_FILES['picture']['tmp_name']; $type = $_FILES['picture']['type']; $size = $_FILES['picture']['size']; // get the width & height of the file (we don't need the other stuff) list($width, $height, $typeb, $attr) = getimagesize($tmp_name); ?> <? // if width is over 600 px or height is over 500 px, kill it if($width>3000 || $height>3500) { echo $name . "'s dimensions exceed the 3000x3500 pixel limit."; echo ?> Click here to try again. <? ; // <------this is line 88,

die();
}

// if the mime type is anything other than what we specify below, kill it
if(!(
$type==‘image/jpeg’ ||
$type==‘image/png’ ||
$type==‘image/gif’
)) {
echo $type . " is not an acceptable format.";
echo ?> Click here to try again. <? ; // <-------- line 99 (same issue I guess)
die();
}

// if the file size is larger than 350 KB, kill it
if($size>‘2200000’) {
echo $name . " is over 2MB. Please make it smaller." ;
echo ?> Click here to try again. <? ; // <------- line 106 (same issue)
die();
}

// if your server has magic quotes turned off, add slashes manually
if(!get_magic_quotes_gpc()){
$name = addslashes($name);
}

// open up the file and extract the data/content from it
$extract = fopen($tmp_name, ‘r’);
$content = fread($extract, $size);
$content = addslashes($content);
fclose($extract);

// connect to the database
include “connecttoserver.php”;

// the query that will add this to the database
$addfile = "INSERT INTO files (name, size, type, content ) ".
“VALUES (’$name’, ‘$size’, ‘$type’, ‘$content’)”;

mysql_query($addfile) or die(mysql_error());

// get the last inserted ID if we’re going to display this image next
$inserted_fid = mysql_insert_id();

mysql_close();

// display the image
?>

<? echo $name; ?>
Unable to view image #<? echo $inserted_fid; ?>
upload more images
<? // we still have to close the original IF statement. If there was nothing posted, kill the page. }else{die("No uploaded file present"); } ?> [/php]

Hi there,

Remove the echo and the ; around your html - it is uneccesary. Just close your PHP tags, write HTML and reopen your tags. The HTML will be automatically printed out.

Would you be kind enough to show me an example. Not too sure what you want me to do. Thank you in advanced :slight_smile:

Hi,

Here is the code replace with your old code
[php]

<?php // if something was posted, start the process... if(isset($_POST['upload'])) { // define the posted file into variables $name = $_FILES['picture']['name']; $tmp_name = $_FILES['picture']['tmp_name']; $type = $_FILES['picture']['type']; $size = $_FILES['picture']['size']; // get the width & height of the file (we don't need the other stuff) list($width, $height, $typeb, $attr) = getimagesize($tmp_name); ?> <? // if width is over 600 px or height is over 500 px, kill it if($width>3000 || $height>3500) { echo $name . "'s dimensions exceed the 3000x3500 pixel limit."; ?> Click here to try again. <? // <------this is line 88,

die();
}

// if the mime type is anything other than what we specify below, kill it
if(!(
$type==‘image/jpeg’ ||
$type==‘image/png’ ||
$type==‘image/gif’
)) {
echo $type . " is not an acceptable format.";
?> Click here to try again. <? // <-------- line 99 (same issue I guess)
die();
}

// if the file size is larger than 350 KB, kill it
if($size>‘2200000’) {
echo $name . " is over 2MB. Please make it smaller." ;
?> Click here to try again. <? // <------- line 106 (same issue)
die();
}

// if your server has magic quotes turned off, add slashes manually
if(!get_magic_quotes_gpc()){
$name = addslashes($name);
}

// open up the file and extract the data/content from it
$extract = fopen($tmp_name, ‘r’);
$content = fread($extract, $size);
$content = addslashes($content);
fclose($extract);

// connect to the database
include “connecttoserver.php”;

// the query that will add this to the database
$addfile = "INSERT INTO files (name, size, type, content ) ".
“VALUES (’$name’, ‘$size’, ‘$type’, ‘$content’)”;

mysql_query($addfile) or die(mysql_error());

// get the last inserted ID if we’re going to display this image next
$inserted_fid = mysql_insert_id();

mysql_close();

// display the image
?>

<? echo $name; ?>
Unable to view image #<? echo $inserted_fid; ?>
upload more images
<? // we still have to close the original IF statement. If there was nothing posted, kill the page. }else{die("No uploaded file present"); } ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service