I am trying to upload files that mostly contain images, from a form I have created via a module. The files upload fine - I can see them in the public folder that was created (while browsing the directory structure), but when I go to view the files from the link provided after the upload, the link seems to point to a url that does not pull up the file. I get either a "page not found" error or a "access denied" error. Since I wanted to customize where and how the file upload elements show on the page, I am using the UpAPI along with the upfield elements. The Upload module or the Attachment module seem to position the fields at the bottom and I don't know how to theme them differently. Also I don't know if I can have multiple upload fields on the same form with those two modules. I can do that with UpAPI and upfield.
The folder I have created is "uploadedfiles" via the Admin->site configuration->File System. The form I have created that does the upload looks like
Some content xxxxxxxxxxxx
Upload singe file here
xxxxxxxxxxxxxxxxx
x x Upload Button
xxxxxxxxxxxxxxxxx
Some more content xxxxxxx
I have looked everywhere to understand how the links to files that get uploaded work, to no avail!
Can someone please help???
Thanks in advance!
Comments
(no title)
It would be useful to mention (a) what is the wrong URL which the links contain and (b) how are you setting it?
Also look how the filefield and imagefield modules work (they both upload files in CCK fields).
File Upload Links
Thanks for your response. I will try and detail out what the URL is and how it is getting set.
1) Once the file gets uploaded, the URL appears as - http://localhost/drupal/?q=upapi/download/filename.jpg
2) The way it is getting set is what I am lost on. I am not able to determine where upapi/download is getting set. I have checked through the Upapi module as well as the upfield module, but I am not good at all with PHP so not able to detect where that is getting set. Any help there will be greatly appreciated! In my form field though here is the code piece that is uploading the file -
I will definitely look through the fielfield and imagefield modules. But if I understood how upapi/download is getting set, maybe I can figure this one out....
(no title)
http://localhost/drupal/?q=upapi/download/filename.jpg is not a valid URL for a real file.
It should be http://localhost/drupal/upapi/download/filename.jpg
Taking a quick look, I notice in upapi_example.module:
This will work when Clean URLs are on, but will break when Clean URLs are off.
It seems the l() function is inappropriate for files, except if you give it a *full url* of a file.
Probably the URL should have been constructed with function http://api.drupal.org/api/function/file_create_url/5
Thanks again for looking
Thanks again for looking into the details.
I actually had a mistake in my previous post. The link is showing up as http://localhost/drupal/?q=upapi/download/node# and when I click on that, it comes back with the "Access Denied" message. What I am frustrated with is that with upapi_example (which adds fields to a Story node), everything works fine, but when I try it on my node, it fails.
So when you say "URL should have been constructed with function http://api.drupal.org/api/function/file_create_url/5" are your suggesting that I change the way the URL is constructed now via upapi_download_path and use the api as provided in the link you pointed out.
Thanks.
(no title)
If the upapi_example links were working OK without Clean URLs enabled, then I was probably wrong. Still, even without the # at the end, the link looks wrong for a file.
What I meant was, for example, either to replace upapi_download_path($file) with file_create_url(upapi_download_path($file)) in the l() function, or to construct the link yourself without l().
About the "#", notice the arguments in http://api.drupal.org/api/function/l/5. That could have been caused by putting something except NULL in the 5th argument ($fragment),
In any case, maybe you could get more specific advice in the module's issues queue
http://drupal.org/project/issues/upapi
Thanks. I have posted there
Thanks. I have posted there as well, but have not received any responses yet. Hence reaching out. Since I am still learning Drupal, I don't understand lot of the different aspects - what does the .l() do? Does it call a function within upapi.module? In the upAPI module I noticed there is a upapi_download_path and a upapi_download_url. I am trying to figure out how I can call upapi_download_url. Simply replacing it in my node or upapi_example, does not seem to call that function.
Also, when I put in http://localhost/drupal/?q=upapi/download/n# the # was a way for me to say n# was a number. The # does not show up in the link.
Thanks again. Appreciate your efforts to help me out!
(no title)
Function l() is a Drupal API function which is used by upapi_example to produce its links. For the reasons I explained, the links it produces are inappropriate for files under some circumstances.
But if upapi_example works, as you said, it is possible that I don't understand at all how upapi works, and that it is not trying to produce a file URL but only a virtual URL which it will process itself. I just don't know.