How image uploads work
The image upload system integrates with diary entries:- Upload images when creating or editing entries
- One image per entry (replacing the previous image if you upload a new one)
- Images are stored in server storage and linked to your entry
- Supported formats include common image types (JPEG, PNG, GIF, etc.)
Images are optional—you can create entries with text only. Adding an image is a great way to capture visual memories alongside your written thoughts.
Uploading an image
Attach an image to a new or existing diary entry.Write your entry text
Fill in the body field with your diary content. Text is required, but images are optional.
Select your image
Choose an image file from your device:
- Common formats: JPEG, JPG, PNG, GIF, WebP
- Make sure the file is a valid image
- File size limits may apply (check with your administrator)
Upload process
When you upload an image:- File validation: The system checks that a file was uploaded
- Storage: Image is saved to
storage/app/public/uploads/with a unique path - Database record: An
ImageEntryrecord is created with:name: Original filename (e.g., “vacation.jpg”)path: Storage path (e.g., “uploads/abc123.jpg”)entry_id: Link to your diary entry
- Association: The image is linked to your entry for display
Images are stored in Laravel’s public storage disk, making them accessible for display while keeping the original files secure.
Viewing images
Images attached to entries are displayed automatically:- Your entries: See your images when viewing your own diary
- Shared entries: Friends can see images on entries shared with them
- Entry detail: Full-size or scaled image appears with the entry text
- Thumbnails: List views may show smaller previews
Image display
The system retrieves images by:- Loading the entry from the database
- Accessing the
imageEntryrelationship (one-to-one) - Fetching the file from storage using the saved path
- Displaying in the UI with appropriate HTML/CSS
Updating images
Replace or remove images on existing entries.Replacing an image
Old image cleanup
When you save, the system automatically:
- Deletes the old image file from server storage
- Removes the old database record
- Uploads and saves the new image
- Creates a new database record
Removing an image
Delete an attached image without adding a replacement:Clear the image field
Remove or clear the file upload field (specific UI depends on your form—may be a “Remove” button or clearing the input).
Keep existing image
If you edit an entry but don’t change the image field:- The existing image remains attached
- No upload or deletion occurs
- Entry retains the current image
- Replace image
- Remove image
- Keep image
Upload a new file → Old image deleted, new image saved.
Image storage and cleanup
MyDiary manages image files carefully to avoid orphaned files and storage bloat.Storage location
- Disk: Laravel’s public storage disk
- Directory:
storage/app/public/uploads/ - Access: Files are accessible via public URLs for display
- Naming: Laravel generates unique filenames to prevent conflicts
Automatic cleanup
The system automatically deletes image files in these scenarios:Entry deletion
Entry deletion
When you delete a diary entry:
- The database cascade deletes the
ImageEntryrecord - The system should clean up the file (implementation may vary)
- Prevents orphaned images
Image replacement
Image replacement
When uploading a new image to an entry:
- Old file is explicitly deleted from storage
- Old database record is removed
- New file and record are created
Image removal
Image removal
When clearing an image field on update:
- File is deleted from storage
- Database record is removed
- Entry continues without an image
File cleanup happens automatically in the controller. You don’t need to manually manage storage—the system handles it for you.
Image permissions
Image access follows entry privacy settings:- Owner: You can always see images on your entries
- Shared friends: Friends can see images on entries shared with them
- Private entries: Images on private entries are only visible to you
- Modification: Only entry creators can upload, replace, or delete images
Security considerations
Best practices
Optimize image size
Optimize image size
Before uploading:
- Resize very large images to reasonable dimensions (e.g., 1920px max width)
- Compress images to reduce file size
- Use web-friendly formats (JPEG for photos, PNG for graphics)
Use descriptive filenames
Use descriptive filenames
Name your images meaningfully before uploading (e.g., “birthday_2026.jpg” instead of “IMG_1234.jpg”). The original name is preserved in the database and may help you identify entries later.
Respect storage limits
Respect storage limits
If your MyDiary instance has storage quotas:
- Don’t upload unnecessarily large files
- Delete old entries with images you no longer need
- Be mindful of how many image entries you create
Consider privacy
Consider privacy
Before attaching an image:
- Review who will see it based on entry visibility
- Avoid images with sensitive personal information
- Be cautious with photos containing identifiable people or locations
Back up important images
Back up important images
MyDiary stores your images, but:
- Keep local copies of irreplaceable photos
- Export or download images you don’t want to lose
- Remember that deleting an entry deletes its image
Common image scenarios
- Creating entry with image
- Adding image to existing entry
- Updating entry text without changing image
- Removing all content
- Write your diary text
- Upload an image file
- Set visibility and sharing
- Save—entry appears with text and image
Troubleshooting
Image won't upload
Image won't upload
Possible causes:
- File is too large (check size limits)
- Unsupported file format (use JPEG, PNG, GIF)
- Server storage is full (contact administrator)
- Network issue during upload (try again)
Image doesn't display
Image doesn't display
Possible causes:
- File path is broken (may require admin assistance)
- Storage symlink not created (Laravel setup issue)
- Image was deleted manually from server
- Browser caching issue (refresh the page)
Can't remove image
Can't remove image
Make sure:
- You’re the entry creator (only owners can modify)
- You’re properly clearing the file field in the edit form
- The form supports image removal (UI may vary)
Old image still shows after replacing
Old image still shows after replacing
Try:
- Refreshing the page (browser cache)
- Clearing browser cache
- Verifying the new image actually uploaded
- Checking that you clicked Save/Update
Technical implementation details
Technical implementation details
Image upload functionality is implemented in
EntryController.php with the following features:Upload on create:- Checks if file exists:
$req->hasFile('file') - Stores file:
$file->store('uploads', 'public')using Laravel’s public disk - Creates record: New
ImageEntrywith name, path, and entry_id
- Checks for new file upload
- If new file: Deletes old file with
unlink(), deletes old record, stores new file, creates new record - If field cleared: Deletes old file and record
- If unchanged: No action taken
- Manual deletion in controller using
unlink(storage_path($path)) - Database record deletion via
$entry->imageEntry->delete() - Path stored in
image_entriestable:pathcolumn
image_entriestable with id, name, path, entry_id, timestamps- Foreign key: entry_id references entries(id) with cascade delete
- One-to-one relationship: Entry
hasOneImageEntry
- Uses Laravel’s
publicdisk (configured in config/filesystems.php) - Default path: storage/app/public/uploads/
- Requires storage:link artisan command for public access