Jump to content

[SOLVED] & Symbol


Bricktop

Recommended Posts

Hello there!

 

I've built a simple gallery system which allows for users to upload images via a simple upload form.  The page that holds this form also displays the images and allows users to delete images.  Images are stored in a MySQL database.  Everything works great apart from when the following happens:

 

If a user uploads a file with an "&" symbol in the filename, the image does not display and you are unable to delete the image from the database using the delete option.

 

It only happens with images with the "&" symbol, strip slashes does not resolve it - I know I'm missing something obvious here.

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

when a user uploads an image, are you giving that image the same name as the uploaded one? like, if I upload main.jpg is that what you're calling it? If so, I recommend renaming it something with a unique name(like the username plus the timestamp or the image's id in the database).

 

Otherwise, are you filtering the images before uploading? Perhaps you're doing htmlentities() and it's changing the & into something else(I think it's & but not exactly sure). If that's what you're doing, I'd still suggest my first suggestion

Link to comment
Share on other sites

Hi people, thanks for the replies. Here is the code for the actual upload:

 

function uploadImage()
{
global $settings;

		$path = $settings['uploadpath'];
		$uploadedfile = $_FILES['image']['tmp_name'];	
		$description = $_POST['description'];
		$filename2 = $_FILES['image']['name'];

	if ( $uploadedfile == "" )
	{	

		$content = '<font color="red">Please select a file to upload</font>';
		$time = 4;

	}
	else
	{
	 	$src = imagecreatefromjpeg($uploadedfile);
	 	list($width,$height)=getimagesize($uploadedfile);

		$newwidth=700;
		$newheight=($height/$width)*700;
		$tmp=imagecreatetruecolor($newwidth,$newheight);

		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

		$filename = $settings['uploadpath'] . $_FILES['image']['name'];
		imagejpeg($tmp,$filename,100);

		if (strlen($_FILES['image']['name']) > 0)
		{
			chmod($settings['uploadpath'] . $_FILES['image']['name'], 0644);
		}




		$sql = mysql_query("INSERT INTO gallery (path,filename,description) VALUES ('$path','$filename2','".addslashes($description)."')") or die(mysql_error());

		$content = 'Your image has been uploaded';

		$time = 2;
	}

user_redirect($_SERVER['PHP_SELF'].'?fct=gallery',$time,$content);
}

 

Please could someone just tell me how I can change the code so when an image is uplaoded containing an "&" symbol in the filename, it renames the "&" to "and". I know I need to do a string replace but am unsure of the syntax and where to place the string replace code.

 

Thanks a lot!

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.