Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks for the help.I had a permissions and directory error after that, but i sorted that one out, but then i get this error and i don't know what this means ...The file has been uploadedWarning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\admin\includes\add_plant.php:45) in C:\Program Files\xampp\htdocs\admin\includes\add_plant.php on line 69BTW....All data is going into db correctly now, although the image still isn't being uploaded/moved. Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 The problem i now withheader(sprintf("Location: %s", $insertGoTo));You can't call header once data has already been output to the browser. In your case you have sent the "Your file has been uploaded message"I'd remove the message. As you immediately want to go to another page the user wouldn't see it anyway.Or, instead of header(), output a meta-refresh tag with a delay of a couple of seconds so user can read message before it goes to the nex page. Link to comment Share on other sites More sharing options...
Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks again.....I have removed the message, but the page doesn't get forwarded on, and the image still isn't getting uploaded.[code] mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error()); $insertGoTo = "plants.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); exit;[/code] Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 Are you getting an error message still?The file isn't uploaded because that section of code is still using the non-existent 'image_name' index instead of 'name'[quote] $uploaddir = '/plants/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['image_name']); if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir)) { echo "The file ". basename( $_FILES['userfile']['image_name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; }[/quote]On reading that bit of code again, you need to change code so that in the event the upload fails you do not update the db. Link to comment Share on other sites More sharing options...
Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks once again....I changed the image_name to name, but the code you mentioned is non existent now as i commented it out due to the header problem. Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 As a minimum you need this to store the uploaded file$uploaddir = '/plants/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir); Link to comment Share on other sites More sharing options...
Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Changed the layout so that if there is an error then it dies, but it still enters the info into the db, it doesn't mention any error, but the image still isn't in the correct directory :([code] $uploaddir = '\plants'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir)) { $insertSQL = sprintf("INSERT INTO plants (image_name, image_type, image_size, path, plant_name, plant_type, planting_months, blooming_season, plant_description) VALUES ('%s', '%s', '%s', '%s', %s, %s, %s, %s, %s)", $fileImagename, $fileImagetype, $fileImagesize, $uploaddir, GetSQLValueString($_POST['plant_name'], "text"), GetSQLValueString($_POST['plant_type'], "text"), GetSQLValueString($_POST['planting_months'], "text"), GetSQLValueString($_POST['blooming_season'], "text"), GetSQLValueString($_POST['plant_description'], "text")); mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error()); $insertGoTo = "plants.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); exit; } else{ echo "There was an error uploading the file, please try again!"; }} ?>[/code] Link to comment Share on other sites More sharing options...
Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Is the uploaddir path ok, or should it be a complete path?Thanks,Steve Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 if(move_uploaded_file($_FILES['userfile']['tmp_name'], [color=red]$uploaddir[/color])) {Oops - should be $uploadfileIf that doesn't work, try if(move_uploaded_file($_FILES['userfile']['tmp_name'], realpath($uploadfile))) { Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 BTW, now you've changed the value of $uploaddir, you will get something like\plantsflower.jpgin $uploadfile instead of/plants/flower.jpg.Better to use '/' instead of '\' even on Win systems. Link to comment Share on other sites More sharing options...
Stevis2002 Posted September 5, 2006 Author Share Posted September 5, 2006 Barand....You my friend are a complete legend...a saint of all patient programmers!!!With a little messing, i got rid of the error statement completely...don't need it, due to the fact that if there is a problem, the script wont go onto the forwarding page anyway, so i will now there is a prob, as the script is just to enter the info into the db anyway, and only i will be doing that!I can manage the data layout and all that jazz myself for the users end.So, Thanks once more for the patience and understanding you have with us [s]dunces[/s] newbies.Steve Link to comment Share on other sites More sharing options...
bm4499 Posted October 27, 2008 Share Posted October 27, 2008 Hi All,Does anyone has an example of the code in the [b]/Connections/localhost.php [/b] file?thanks in advancebm Link to comment Share on other sites More sharing options...
Barand Posted October 27, 2008 Share Posted October 27, 2008 Why are you bumping a two year old topic? Link to comment Share on other sites More sharing options...
Recommended Posts