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
https://forums.phpfreaks.com/topic/118403-solved-amp-symbol/
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
https://forums.phpfreaks.com/topic/118403-solved-amp-symbol/#findComment-609477
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
https://forums.phpfreaks.com/topic/118403-solved-amp-symbol/#findComment-609548
Share on other sites

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.