Jump to content

Recommended Posts

Hope someone can help with this.

At the moment I have a form that includes an image upload, along with various other fields that get dumped into a database.

The file name is dumped into a File_Name field also, and currently trims it so that only the filename goes into the database rather than the full path,

ie image.jpg instead of c:/pictures/image.jpg

However, we've just noticed an issue whereby truncation is also taking place after the ' character.

ie  c:/pictures/bob's photo is dumping s photo instead of bob's photo.

I can't see anything obvious in the code, but find below some snippets :

The upload to server code :

[code=php:0]if ( is_uploaded_file($_FILES['uploadFile']['tmp_name']) ) {

$destpath = 'Photos/' . basename($_FILES['uploadFile']['name']);

if (!move_uploaded_file($_FILES['uploadFile']['tmp_name'], $destpath) ) {
  echo 'Error moving file ' . $_FILES['uploadFile']['tmp_name'] . ' to ' . $destpath;
}
}[/code]

The dump fields into database code :

[code=php:0]$FTG_uploadFile = AddSlashes($FTGuploadFile);
$FTG_Title = AddSlashes($FTGTitle);
$FTG_Link_ID = AddSlashes($FTGLink_ID);
$FTG_Supplier = AddSlashes($FTGSupplier);
$FTG_Rights = AddSlashes($FTGRights);
$FTG_Rights_Details = AddSlashes($FTGRights_Details);
$FTG_Credit = AddSlashes($FTGCredit);
$FTG_Image_Size = AddSlashes($FTGImage_Size);
$FTG_Orientation = AddSlashes($FTGOrientation);
$FTG_Year = AddSlashes($FTGYear);
$FTG_Country = AddSlashes($FTGCountry);
$FTG_Admin = AddSlashes($FTGAdmin);
$FTG_Region = AddSlashes($FTGRegion);
$FTG_Easting = AddSlashes($FTGEasting);
$FTG_Northing = AddSlashes($FTGNorthing);

$mysql_link = @mysql_connect("localhost", "root", "Fishnish");



if (mysql_errno() == 0) {

@mysql_select_db("photolibrary", $mysql_link);


}

if (mysql_errno() == 0) {

$sqlcmd = "INSERT INTO photos(Photo_File, Title, Link_ID, Supplier, Rights, Rights_Details, Credit, Image_Size, Orientation, Year, Country, Admin, Region, Easting, Northing) VALUES('$FTG_uploadFile', '$FTG_Title', '$FTG_Link_ID', '$FTG_Supplier', '$FTG_Rights', '$FTG_Rights_Details', '$FTG_Credit', '$FTG_Image_Size', '$FTG_Orientation', '$FTG_Year', '$FTG_Country', '$FTG_Admin', '$FTG_Region', '$FTG_Easting', '$FTG_Northing')";

@mysql_query($sqlcmd, $mysql_link);
$Photo_ID = mysql_insert_id ();



}[/code]

Any ideas what I need to modify / add to stop it truncating after ' ?

Cheers,
Iain
Link to comment
https://forums.phpfreaks.com/topic/31338-truncating-a-path-when-uploading-a-photo/
Share on other sites

I personally wouldn't be interested in finding out why it's doing it, I'd be concentrating on creating file names that don't contain apostrophes in the first place.

Maybe run [code=php:0]$_FILES['uploadFile']['name'][/code] through some checks first to make sure that it contains only alpha-numeric characters before renaming the file to it.

Regards
Huggie
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.