Jump to content

PHP Upload problem - apostrophe


kamal213

Recommended Posts

Hi Guys

 

I have this PHP Upload Scripts below which uploads file of customers into the customers folder and at the same time inserts the file path into the database.

 

The problems is for name like O'hare or O'neil its uploads into the customers folder but does not insert the file path into the database - probably because of the " ' " apostrophe

 

From the code below is there anyway I can deal with this issue?  Thanks alot

 

<?php 
//This php block of code will takecare of inserting the upload variables into the db

if(isset($_POST['submitbutton'])) {
$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';		
$target_path = $target_path . basename( $_FILES['upload']['name']);
$manager= mysql_real_escape_string($_POST['username']);
$upload =  $_FILES['upload']['name'];
$check_id = mysql_real_escape_string($_POST['id']);
$submitbutton= mysql_real_escape_string($_POST['submitbutton']);



if($submitbutton)
{
if($manager&&$upload)
{
if (file_exists($target_path))
{
echo $_FILES["upload"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path);
echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"];

$insert=mysql_query("INSERT INTO img_up (username,upload,id,target_path,img_date) VALUES ('$manager','$upload','$check_id','$target_path', now()) ");

		// Where the file is going to be placed 
		$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';

		/* Add the original filename to our target path.  
		Result is "uploads/filename.extension" */
		$target_path = $target_path . basename( $_FILES['upload']['name']); 

		$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';

		$target_path = $target_path . basename( $_FILES['upload']['name']); 

		if (file_exists($target_path))
		{
		echo $_FILES["upload"]["name"] . " already exists. ";
		}
		else
		{
		move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path);
		echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"];
		}


}
}
else
{
echo "There was an error uploading the file, please try again!";
}
}
 header("location: mainupload_complete.php?id=$check_id"); 
}
?>

Link to comment
Share on other sites

I have included it just as shown below but it doesnt seem to work am obviously doin something wrong.

 

<?php 
//This php block of code will takecare of inserting the upload variables into the db

if(isset($_POST['submitbutton'])) {
$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';		
$target_path = $target_path . basename( $_FILES['upload']['name']);
$manager= mysql_real_escape_string($_POST['username']);
$upload =  $_FILES['upload']['name'];
$upload = str_replace("'","",$upload);
$check_id = mysql_real_escape_string($_POST['id']);
$submitbutton= mysql_real_escape_string($_POST['submitbutton']);


if($submitbutton)
{
if($manager&&$upload)
{
if (file_exists($target_path))
{
echo $_FILES["upload"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path);
echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"];

$insert=mysql_query("INSERT INTO img_up (username,upload,id,target_path,img_date) VALUES ('$manager','$upload','$check_id','$target_path', now()) ");

		// Where the file is going to be placed 
		$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';

		/* Add the original filename to our target path.  
		Result is "uploads/filename.extension" */
		$target_path = $target_path . basename( $_FILES['upload']['name']); 

		$target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/';

		$target_path = $target_path . basename( $_FILES['upload']['name']); 

		if (file_exists($target_path))
		{
		echo $_FILES["upload"]["name"] . " already exists. ";
		}
		else
		{
		move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path);
		echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"];
		}


}
}
else
{
echo "There was an error uploading the file, please try again!";
}
}
 header("location: mainupload_complete.php?id=$check_id"); 
}
?>[/code[]

Link to comment
Share on other sites

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.