Bricktop Posted August 6, 2008 Share Posted August 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 you might be able to use str_replace("&",""); Regards ACE Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted August 6, 2008 Share Posted August 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted August 6, 2008 Share Posted August 6, 2008 Hang on, show us some code. Is the name not showing, or is the picture not showing? Is it in a thumbnail form, or a full sized form? ---------------- Now playing: Enter Shikari - Mothership (Demo) via FoxyTunes Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 6, 2008 Author Share Posted August 6, 2008 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! Quote Link to comment Share on other sites More sharing options...
Bricktop Posted August 6, 2008 Author Share Posted August 6, 2008 Worked it out in the end! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted August 6, 2008 Share Posted August 6, 2008 ^ did it work by you doing the string replace? Because if that's all you replaced, you need to do tests for other symbols like a space, percent, etc. Show your working code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.