Hi people. Having trouble with an upload script I found online. Everything works great on my comp, but i get this error: Parse error: syntax error, unexpected '{' in /home/pax3wrek/public_html/new/new/listing-3.php on line 8 when i attempt it online.
the offending php:
<?php
// check if a file was submitted
if(!isset($_FILES['userfile'])) {
echo '<p>Select a file</p>';
}
else
{
try {
upload();
echo '<p>Submitted</p>';
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
?>
This error prevents the page from loading; it doesnt appear after the script is run.
here is the rest of the script :
<?php
// the upload function
function upload(){
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
// check the file is less than the maximum file size
if($_FILES['userfile']['size'] < 200000000)
{
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
// $imgData = addslashes($_FILES['userfile']);
// get the image info..
$size = getimagesize($_FILES['userfile']['tmp_name']);
$dealname=$_POST['dealname'];
$descrip=$_POST['descrip'];
$price=$_POST['price'];
// put the image in the db...
// database connection
mysql_connect("localhost", "username", "password") OR DIE (mysql_error());
// select the db
mysql_select_db ("pax3wrek_hvware") OR DIE ("Unable to select db".mysql_error());
// our sql query
$sql = "INSERT INTO testblob2
(image_id , image_type ,image, image_size, image_name, dealname, descrip, price)
VALUES
('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}', '{$dealname}', '{$descrip}', '{$price}')";
// insert the image
if(!mysql_query($sql)) {
echo 'Unable to upload file';
}
}
}
else {
// if the file is not less than the maximum allowed, print an error
echo
'<div>File exceeds the Maximum File limit</div>
<div>Maximum File limit is </div>
<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div>
<hr />';
}
}
?>
The rest is just the HTML forms.
Is it strange that it works on my computer (wamp server) but not on my website?
I'm just starting out and have a limited grasp of everything. I understand what is happening in the script but simply wouldn't have a clue how to start from scratch myself.
Thanks in advance