Sabrina Posted June 26, 2011 Share Posted June 26, 2011 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 // 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 ?> <a href="form.html">Click here</a> 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 ?> <a href="form.html">Click here</a> 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 ?> <a href="form.html">Click here</a> 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 ?> <div align="center"> <strong><? echo $name; ?><br> </strong><img name="<? echo $name; ?>" src="dbview.php?fid=<? echo $inserted_fid; ?>" alt="Unable to view image #<? echo $inserted_fid; ?>"> <br> <a href="form.html">upload more images</a> </div> <? // we still have to close the original IF statement. If there was nothing posted, kill the page. }else{die("No uploaded file present"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240480-need-help-with-simple-php-upload-code/ Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2011 Share Posted June 26, 2011 Did you try removing the unexpected semicolon to see what would happen? Quote Link to comment https://forums.phpfreaks.com/topic/240480-need-help-with-simple-php-upload-code/#findComment-1235178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.