-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_storage_symlink_fixed.php
More file actions
145 lines (126 loc) · 4.74 KB
/
create_storage_symlink_fixed.php
File metadata and controls
145 lines (126 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Storage Symlink Creator for eunixmac_api setup
* IMPORTANT: Delete this file immediately after use!
*/
if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) {
die('This script should only be run on production server!');
}
// Correct paths for your setup
$publicPath = '/home/eunixmac/public_html'; // Where symlink will be created
$storagePath = '/home/eunixmac/eunixmac_api/storage/app/public'; // Where storage actually is
$symlinkPath = $publicPath . '/storage';
echo "<h2>Storage Symlink Creator</h2>";
echo "<pre>";
// Step 1: Verify paths exist
echo "Step 1: Verifying paths...\n";
echo "Public Path: {$publicPath}\n";
echo "Storage Path: {$storagePath}\n";
echo "Symlink Path: {$symlinkPath}\n\n";
if (!is_dir($publicPath)) {
die("❌ ERROR: Public directory not found at: {$publicPath}\n");
}
if (!is_dir($storagePath)) {
die("❌ ERROR: Storage directory not found at: {$storagePath}\n");
}
echo "✅ Both directories exist\n\n";
// Step 1b: Create ads directory if it doesn't exist
$adsPath = $storagePath . '/ads';
if (!is_dir($adsPath)) {
echo "Step 1b: Creating ads directory...\n";
if (mkdir($adsPath, 0755, true)) {
echo "✅ Ads directory created at: {$adsPath}\n\n";
} else {
echo "⚠️ WARNING: Could not create ads directory. It will be created automatically on first upload.\n\n";
}
} else {
echo "Step 1b: Ads directory already exists\n\n";
}
// Step 2: Check if symlink already exists
echo "Step 2: Checking existing symlink...\n";
if (file_exists($symlinkPath)) {
if (is_link($symlinkPath)) {
$currentTarget = readlink($symlinkPath);
echo "⚠️ Symlink already exists, pointing to: {$currentTarget}\n";
// Remove old symlink
if (unlink($symlinkPath)) {
echo "✅ Old symlink removed\n\n";
} else {
die("❌ ERROR: Could not remove old symlink\n");
}
} elseif (is_dir($symlinkPath)) {
echo "⚠️ Directory named 'storage' exists (not a symlink)\n";
echo "❌ ERROR: Please manually delete the 'storage' directory in public_html via cPanel File Manager\n";
die("Then run this script again.\n");
} else {
echo "⚠️ File named 'storage' exists\n";
if (unlink($symlinkPath)) {
echo "✅ File removed\n\n";
} else {
die("❌ ERROR: Could not remove file\n");
}
}
} else {
echo "✅ No existing symlink found\n\n";
}
// Step 3: Create the symlink
echo "Step 3: Creating symlink...\n";
if (symlink($storagePath, $symlinkPath)) {
echo "✅ SUCCESS! Symlink created successfully\n\n";
} else {
die("❌ ERROR: Failed to create symlink. Contact your hosting provider.\n");
}
// Step 4: Verify the symlink
echo "Step 4: Verifying symlink...\n";
if (is_link($symlinkPath)) {
$target = readlink($symlinkPath);
echo "✅ Symlink verified!\n";
echo " Link: {$symlinkPath}\n";
echo " Points to: {$target}\n\n";
} else {
die("❌ ERROR: Symlink verification failed\n");
}
// Step 5: Check if images directory exists
echo "Step 5: Checking ads images directory...\n";
if (is_dir($adsPath)) {
$imageCount = count(glob($adsPath . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE));
echo "✅ Ads directory exists with {$imageCount} images\n\n";
} else {
echo "⚠️ Ads directory doesn't exist. It will be created when first ad is posted.\n\n";
}
// Step 6: Test access
echo "Step 6: Testing symlink access...\n";
if (is_readable($symlinkPath)) {
echo "✅ Symlink is readable\n";
} else {
echo "⚠️ WARNING: Symlink might not be readable. Check permissions.\n";
}
if (is_executable($symlinkPath)) {
echo "✅ Symlink is executable\n";
} else {
echo "⚠️ WARNING: Symlink might not be executable. Check permissions.\n";
}
echo "\n";
echo "=====================================\n";
echo "✅ SYMLINK CREATION COMPLETED!\n";
echo "=====================================\n\n";
echo "Next steps:\n";
echo "1. ❌ DELETE THIS FILE IMMEDIATELY for security!\n";
echo "2. Upload images to: /home/eunixmac/eunixmac_api/storage/app/public/ads/\n";
echo "3. Test image URLs: https://{$_SERVER['HTTP_HOST']}/storage/ads/your-image.jpg\n";
echo "4. Post a new ad with images to test the upload flow\n\n";
// List some sample images if they exist
if (is_dir($adsPath)) {
$images = glob($adsPath . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
if (!empty($images)) {
echo "Sample image URLs you can test:\n";
foreach (array_slice($images, 0, 3) as $imagePath) {
$imageName = basename($imagePath);
echo "https://{$_SERVER['HTTP_HOST']}/storage/ads/{$imageName}\n";
}
echo "\n";
}
}
echo "</pre>";
echo "<h3 style='color: red;'>⚠️ DELETE THIS FILE NOW!</h3>";
?>