Jump to content

String function to get file name from upload field (i.e. no directory path!)


rachwilbraham

Recommended Posts

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!!!  :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.