WordPress.org

Codex

User:Lolrus/Using Attachments

This is a draft rewrite of Using Image and File Attachments trying to update it for 2.2+

Wordpress attachments are files you upload and "attach" to a post or Page. Like posts, they have a title and description, and can have comments.

You can display or link to your attachments from the post editor, and you can use certain themes or plugins to do more.

Contents

Requirements

To upload files, Wordpress needs to be able to write to the wp-content/uploads folder. Try giving write access to the owner first, then group or world (public, everyone) if that doesn't work.

To make thumbnail images, Wordpress needs the GD extension (check your server info). You can upload images (and any other files) without the GD extension, but you won't get automatic thumbnails.

How to upload an attachment

From the write/edit post or page panel,

  1. Click the Upload tab
  2. Click the Browse button and choose a file on your computer
  3. Write a title and (optional) description
  4. Click the Upload » button

The active tab now switches to "Browse" and you can insert the new attachment into your post if you like, but you don't have to ( see get_children) — the new attachment has been saved.

If this was a new post, click the Save or Publish button (otherwise your new attachment will be orphaned).

Errors?

How to show or link to an attachment in a post

From the write/edit post or write/edit page panels,

  1. Choose the "Browse" tab (if you want to choose from the current post's attachments) or the "Browse all" tab (if you want to choose from all attachments).
  2. Click on the attachment you want
  3. Choose how you want to Show your image or link:
    • Thumbnail (shown for on image, if a thumbnail exists) : a smaller image, maximum 128 x 96 pixels (?)
    • Full-size (shown for an image) :
    • Icon (shown for a non-image attachment, if a matching media icon exists)
    • Title : the title of the attachment, as text
  4. Choose what you want to Link to:
    • File : A direct link to the attachment file
    • Page : A link to the attachment page
    • None : No link. Choose this if you just want to display an image
  5. Click the Send to editor » button; or click the « Back link to choose a different attachment instead.

Editing and deleting attachments

You can edit an attachment's title and description (but not URL) or delete the attachment altogether:

Choose the attachment you want to edit from the Manage → Uploads panel or choose one from the "Browse" tabs on the Edit post/page screen and click the Edit link.

  • Edit the Title or Description fields and click the Save » button; or
  • Click the Delete button to delete the attachment forever; or
  • Click the Cancel link to go back to browsing attachments

Attachments are not deleted when their parent posts are deleted; they just become "orphans". Orphan attachments are no longer reachable by pretty permalinks (/post_name/attachment_name) but can still be found at default URIs (/?attachment_id=N).

It's not yet possible to move an attachment from one parent post to another, or assign orphan attachments to a new parent.

Attachment pages

They show your attachments, with description and comments. See Templates_Hierarchy#Attachment_display

Attachment settings

Attachment files are stored in your wp-content/uploads folder. You can choose to keep them organized in subfolders by date (yyyy/mm) or not on the Options → Misc panel.

Thumbnail dimensions (128 × 128 pixels) and the list of allowed file types can be changed by plugins. In Wordpress 2.3, Administrators can upload any type without restriction.

Troubles

"Unable to create directory [path]. Is its parent directory writable by the server?"
Make sure the folder wp-content/uploads exists and Wordpress can write to it and any subfolders inside.
"The uploaded file could not be moved to [path]…"
Same.
"The uploaded file exceeds the upload_max_filesize directive…" (Upload file too big)
Increase PHP's upload_max_filesize setting or upload a smaller file.
"Fatal error: Allowed memory size … exhausted" (Out of memory)
Increase PHP's memory_limit setting or upload a smaller file.
"File type does not meet security guidelines"
Wordpress does not recognize the file you uploaded as a "safe" type. Make sure your file has the correct name extension, or use a plugin to add new MIME types. Found in admin-functions.php.
"Fatal error: Call to undefined function imagedosomething…"
The GD extension is not installed or it's missing a library needed to process the image type you uploaded. This probably means that your upload succeeded but a thumbnail couldn't be created.
How does the attachment menu work? (Wordpress 2.0)
Some of the "links" in the 2.0 menu act like toggle switches and some act like buttons. Later versions have a better menu.
Attachment page not found (404)
Did you delete the post parent?
If this occurs for attachment URIs like /category/post_name/attachment_name, it's a Wordpress bug (Custom permalinks containing categories are broken for attachments) that has existed since 2.0 and is scheduled for fixing in 2.4. Links to Page attachments (which do not use %category%) will still work.

See also

Appendix: Allowed attachment file types

jpg
jpeg
jpe
image/jpeg
gif
image/gif
png
image/png
bmp
image/bmp
tif
tiff
image/tiff
ico
image/x-icon
asf
asx
wax
wmv
wmx
video/asf
avi
video/avi
mov
qt
video/quicktime
mpeg
mpg
mpe
video/mpeg
txt
c
cc
h
text/plain
rtx
text/richtext
css
text/css
htm
html
text/html
mp3
mp4
audio/mpeg
ra
ram
audio/x-realaudio
wav
audio/wav
ogg
audio/ogg
mid
midi
audio/midi
wma
audio/wma
rtf
application/rtf
js
application/javascript
pdf
application/pdf
doc
application/msword
pot
pps
ppt
application/vnd.ms-powerpoint
wri
application/vnd.ms-write
xla
xls
xlt
xlw
application/vnd.ms-excel
mdb
application/vnd.ms-access
mpp
application/vnd.ms-project
swf
application/x-shockwave-flash
class
application/java
tar
application/x-tar
zip
application/zip
gz
gzip
application/x-gzip
exe
application/x-msdownload