# Image Path Fix Instructions

## Issue
Old user images are not loading with 404 errors like:
```
Page not found (404)
"/home/acbptxvs/public_html/branchbusinessadvance.co.ke/media/kyc/id_documents/FRONT-ID.jpeg" does not exist
```

New user images work fine, but existing users have incorrect image paths in the database.

## Solution
Run the production image path fix script to update database records.

## Steps

### 1. Upload the fix script
Upload `fix_production_image_paths.py` to your cPanel file manager in the same directory as your Django project.

### 2. Run the fix script
In cPanel's "Execute Python Script" feature, run:

```python
python fix_production_image_paths.py
```

OR via SSH (if available):

```bash
cd /path/to/your/django/project
python fix_production_image_paths.py
```

### 3. Test the images
After the script completes:
1. Go to your application
2. View existing user profiles
3. Check that their images now load properly

## What the script does

1. ✅ Scans all users in the database
2. ✅ Identifies incorrect image paths
3. ✅ Updates paths to use correct media URL structure:
   - `kyc/id_documents/filename.jpg`
   - `kyc/selfies/filename.jpg`
   - `kyc/utility_bills/filename.jpg`
   - `profile_images/filename.jpg`
   - etc.
4. ✅ Saves corrected paths to database
5. ✅ Verifies all paths are now correct
6. ✅ Provides sample URLs for testing

## Expected output

You should see:
```
🎉 PRODUCTION IMAGE PATH FIX COMPLETED SUCCESSFULLY!
✅ All image paths have been corrected in the database
✅ Images should now load properly in the application
```

## Example fixes

The script will convert paths like:
- `FRONT-ID.jpeg` → `kyc/id_documents/FRONT-ID.jpeg`
- `selfie_123.jpg` → `kyc/selfies/selfie_123.jpg`
- `utility_bill.pdf` → `kyc/utility_bills/utility_bill.pdf`

## No restart required

Unlike other fixes, this one updates the database only, so no application restart is needed. Changes are immediate.

## Alternative: Run updated setup.py

You can also run the updated `setup.py` which includes this fix:

```python
python setup.py
```

This will run the complete setup process including the image path fixes.

## Verification

After running the fix:
1. Check that old user images now display
2. Verify new user images still work
3. Test the sample URLs provided by the script

## If images still don't load

1. Check file permissions on the media directory
2. Verify the files actually exist on the server
3. Check your web server configuration for serving media files
4. Ensure the .htaccess file in the media directory is correct