rachwilbraham Posted March 4, 2009 Share Posted March 4, 2009 Hello everyone! I am creating an upload file form, and I need to be able to get the file name only (without the directory path) to update the image name field in my mySQL database. I'm doing this in dreamweaver cs4, just in case that makes any difference! Also, the database connections are all fine - we have tested that using a simple text input to update the database. ('userfile'=the form field where the user browses for the file / types in the directory path & file name) So far we have this...: if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "upload")) { $filename = $_FILES['userfile']; echo $filename; $slashpos = strrpos($filename,"\\"); echo $slashpos; $filename = substr($filename,($slashpos+1), strlen($filename)-($slashpos+1)); echo $filename; $updateSQL = sprintf("UPDATE rach230209 SET IMAGENAME=$filename WHERE PRODUCTID=%s", GetSQLValueString($_POST['PRODUCTID'], "int")); mysql_select_db($database_interdevdev, $interdevdev); $Result1 = mysql_query($updateSQL, $interdevdev) or die(mysql_error()); } Can anyone tell me where I am going wrong here?!?! The file is uploading no problem, but no text is going into my database!!! All help is appreciated!!! Link to comment https://forums.phpfreaks.com/topic/147892-string-function-to-get-file-name-from-upload-field-ie-no-directory-path/ Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 Take a look at this - see if this is what you're after... http://uk3.php.net/dirname Link to comment https://forums.phpfreaks.com/topic/147892-string-function-to-get-file-name-from-upload-field-ie-no-directory-path/#findComment-776224 Share on other sites More sharing options...
PFMaBiSmAd Posted March 4, 2009 Share Posted March 4, 2009 $_FILES['userfile'] is an array. To get the file name, use $_FILES['userfile']['name'] Link to comment https://forums.phpfreaks.com/topic/147892-string-function-to-get-file-name-from-upload-field-ie-no-directory-path/#findComment-776257 Share on other sites More sharing options...
rachwilbraham Posted March 4, 2009 Author Share Posted March 4, 2009 Thank you! Problem sorted.... we had to use $filename1 = basename($_FILES['userfile']['name']); Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/147892-string-function-to-get-file-name-from-upload-field-ie-no-directory-path/#findComment-776310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.