WestCoast_BC
asked on
How do I use imagenew if the file name contains spaces
I am trying to use the Codlfusion function imageNew. It works for me if the filename does not contain any spaces. If it does I get an error. For example:
If anyone can shed some light regarding this problem I would very much appreciate it.
<cfset thisImageside=imageNew("/path_to_file/filename.jpg")>
works but<cfset thisImageside=imageNew("/path_to_file/file name with space.jpg")>
gives me an error, I get an Access denied error. I have tried using urlEncodeFormat for the file name but then I get the error that the file does not exist.If anyone can shed some light regarding this problem I would very much appreciate it.
ASKER
If I use parseURL I get the error:
No matching function [PARSEURL] found
ASKER
I do not need to use parseURL because I already have the filename without the path. It looks to me that the example provided comes from: https://www.raymondcamden.com/2013/01/09/CFImage-and-paths-with-spaces
I tried using urlEncodedFormat as suggested in Raymond Camden's article but I get the error that the file does not exist
I tried using urlEncodedFormat as suggested in Raymond Camden's article but I get the error that the file does not exist
parseURL() is the custom function as shown in previous link.
Try another approach:
Try another approach:
<cfset newurl = parts.scheme & "://" & parts.domain & parts.directory & urlEncodedFormat(parts.file)>
<cfoutput><p>#newurl#<p></cfoutput>
<cfimage source="#newurl#" name="yourImage">
ASKER
I have already tried what you suggest but I get the error that the file doesn't exist. Here is my error message:
file or directory [my_path]/images/2%20j%20live%20Ottawa07%2Ejpg not exist
file or directory [my_path]/images/2%20j%20live%20Ottawa07%2Ejpg not exist
Is this file path exist as given accessible in browser?
[my_path]/images/2%20j%20live%20Ottawa07%2Ejpg
ASKER
No, it is a path in my server starting with c:/home/ .....
Can you refer the hosted file from public URL domain? otherwise, you will get permission access error.
Furthermore, you can use double quotes ("") to refer the file name with spaces.
Try this:
Furthermore, you can use double quotes ("") to refer the file name with spaces.
Try this:
<cfset thisImageside=imageNew(""http://yourdomain.com/path_to_file/file name with space.jpg"")>
ASKER
If I use the same code but with a filename that does not contain any spaces then it works fine. In both cases the path to the file is exactly the same.
ASKER
Double quotes causes an error, the page does not run. Given that my test works files that do not contain a space I am confident that my path is correct.
how about replace space with %20 if your existing path is working fine? %2E is dot replacement after encoded.
<cfset thisImageside=imageNew("/path_to_file/file%20name%20with%20space%2Ejpg")>
ASKER
I have tried that. Here is my error message:
To make sure that the file exists I added
file or directory [my_path]/images/2%20j%20live%20Ottawa07%2Ejpg not exist
To make sure that the file exists I added
<img src="[my_path]/images/2%20j%20live%20Ottawa07%2Ejpg" width="300px">
and the image loads fine
I do not use CF and can't provide the exact answer, but I believe your issue is your file name with spaces has to contain quotes. https://docs.microsoft.com/en-us/troubleshoot/windows-server/deployment/filenames-with-spaces-require-quotation-mark
In any of my web apps, I just don't allow the use of spaces in file names. If the image is being uploaded, I just do a string replace to switch out the space for an underscore.
In any of my web apps, I just don't allow the use of spaces in file names. If the image is being uploaded, I just do a string replace to switch out the space for an underscore.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
parseURL: https://cflib.org/udf/parseUrl