Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

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


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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.