CanMan2004 Posted February 12, 2007 Share Posted February 12, 2007 Hi all I've written a script to upload a resize an image, but I cant figure out how I can get it to remove all spaces from the filename, the code is if ($_FILES['image']['name'] != '') { $randy = random(12); $uploadImageDir = '../image_upload/activity_uploads/'.$randy.''; $uploadImage = $uploadImageDir . $_FILES['image']['name']; $uploadImageFormat = $randy.$_FILES['image']['name']; if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadImage) ) { } $imageupload = $uploadImage; createthumb($imageupload,$imageupload,767,'','',411); } else { print"<script>alert ('There was a problem with your image');</script>"; print"<script>document.location='register.php'; </script>"; } Where would I place a str_replace function? Can anyone help? Thanks Dave Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/ Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 trim($filename); you shoudl also check if the file name already exists if so append something to the basename of the file like '_1'. Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182345 Share on other sites More sharing options...
CanMan2004 Posted February 12, 2007 Author Share Posted February 12, 2007 So where should I encorporate trim() into my query? Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182349 Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 $uploadImage = trim($uploadImageDir . $_FILES['image']['name']); Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182356 Share on other sites More sharing options...
CanMan2004 Posted February 12, 2007 Author Share Posted February 12, 2007 Hi Thanks, but that doesnt seem to remove any spaces from the filename Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182371 Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 $uploadImage = $uploadImageDir . $_FILES['image']['name']; $uploadImage = str_replace(" ", "_", $uploadImage); Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182399 Share on other sites More sharing options...
The Little Guy Posted February 12, 2007 Share Posted February 12, 2007 trim only removes spaces from the beginning of the file and the end of the file Quote Link to comment https://forums.phpfreaks.com/topic/38090-image-upload-rename-removing-spaces/#findComment-182416 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.