derekbelcher Posted June 18, 2009 Share Posted June 18, 2009 I am getting a "basename() expects parameter 1 to be string error. Not sure what I am missing. Help? <?php //This is the directory where images will be saved $target = "/departments/athens/images/"; $target = $target . basename($_FILES['photo']); // Connects to your Database mysql_connect("-----") or die(mysql_error()) ; mysql_select_db("p2r71184_photos") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `athensPhoto` VALUES ('$photo')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 The name you use for a variable matters. $_FILES['uploadedfile'] does not exist because the name you have used is $_FILES['photo'] Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/#findComment-858660 Share on other sites More sharing options...
derekbelcher Posted June 18, 2009 Author Share Posted June 18, 2009 that was stupid :-) LOL. I changed uploadedfile to 'photo' and get same error. I (as you can tell) am very new to php. is there a better way to accomplish a photo upload. Basically I want to allow users to upload up to 18 photos into the database. is there a tutorial or idea someone could turn me on to. Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/#findComment-858664 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 Add the code mentioned in the following post - http://www.phpfreaks.com/forums/index.php/topic,257037.msg1209362.html#msg1209362 Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/#findComment-858666 Share on other sites More sharing options...
derekbelcher Posted June 18, 2009 Author Share Posted June 18, 2009 FILES:Array ( [photo] => Array ( [name] => Untitled-2.jpg [type] => image/jpeg [tmp_name] => /tmp/phpFDLJZ5 [error] => 0 => 7574 ) ) Does this make any since? thanks for your help Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/#findComment-858670 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 That makes perfect sense when you have read the documentation for what you are attempting to do - http://us3.php.net/manual/en/features.file-upload.post-method.php And the error is apparently (posting actual error messages help pin down where exactly the problem is in the code) being caused by this line of code - $target = $target . basename($_FILES['photo']); because $_FILES['photo'] is not the name of the uploaded file. $_FILES['photo']['name'] would be the variable that holds the name of the uploaded file. Link to comment https://forums.phpfreaks.com/topic/162708-solved-problem-with-image-upload/#findComment-858676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.