PHP Notice: Undefined offset: 3

Hi

I am a complete Beginner in PHP i am basically using a script i have been given by a supplier to maintain images, basically download them from the supplier so i can then upload them to my website after I “believe” i have edited everything i need to but when i run it i get the error;

PHP Notice: Undefined offset: 3 in C:\inetpub\wwwroot\image_library_maintain_cl.php on line 117

The code in the script is (I have taken account details out);
[php]
#!/usr/bin/php -ddisplay_errors=on -derror_reporting=E_ALL

<?php /** * Application to process Overnight image retrieval: * simply place this script in your cron to run once a night for every * week day and it will grab all of the missing images in your library. * * Terms & Conditions * This sample code to ease the implimentation of Midwich Data Feeds * into your website is subject to the terms and conditions of the GPL * (General Public License). If you do not have a copy it can be * viewed online here: http://www.gnu.org/copyleft/gpl.html * * @author Russell Nash * @author Midwich IT * @version 1.0.0 * @package Image_Library * @subpackage Application * @category Feeds * * @copyright Copyright (c) 2009 Midwich Ltd, EDI Admin * @Created 16/11/2009 * @Updated 16/11/2009 * @Revision 1.0.0 * + 16/11/2009 - Russell Nash * + original application to pplication to process Overnight image retrieval. */ /** * Application to pplication to process Overnight image retrieval: * * @author Russell Nash * @author Midwich IT * @version 1.0.0 * @package Image_Library * @subpackage Application * @category Feeds * * @copyright Copyright (c) 2009 Midwich Ltd, EDI Admin * @Created 16/11/2009 * @Updated 16/11/2009 */ class Image_Library { /** the current version of the script */ const VERSION = '1.0.0'; /** your Midwich account number */ const MIDWICH_ACCOUNT_NUMBER = ''; /** * the invoicing postcode used with Midwich * Replace spaces in the post code with %20 */ const POSTCODE_USED_WITH_MIDWICH = ''; /** * the path where the temporary files will be stored * Paths must NOT end in / */ const PATH_TO_TEMP_DIR = 'c:/image_store/img_temp'; /** * the path where the downloaded image files will be moved to * Paths must NOT end in / */ const PATH_TO_IMAGE_DIR = 'c:/image_store'; /** * the path where the downloaded image thumbnail files will be moved to * Paths must NOT end in / */ const PATH_TO_IMAGE_THUMB_DIR = 'c:/image_store/thumb'; /** the URL to download the updated image feed */ const UPDATE_ZIPFILE_URL = 'http://www.midwich.com/download/zip/image_links/false'; /** the URL to download the updated image file */ const DOWNLOAD_IMAGE_URL = 'http://www.midwich.com/web_services/images'; /** the URL to download the updated pdf feed */ const CSV_FILENAME = 'c:/image_store/image_links.csv'; /** * the command used to unzip the downloaded archive * Windows users need to invoke an unzip program */ const UNZIP_COMMAND = 'unzip -uo '; /**#@+ * @access protected * @var Boolean */ /** * flag to download image thumbnails as well as the product image * @see Image_Library::downloadImage() */ private $blDownloadThumbnails = TRUE; /**#@-*/ /**#@+ * @access protected * @var String */ /** * hold the temporary name for the downloaded archive file * @see Image_Library::downloadUpdateArchive(), Image_Library::extractArchiveContent() */ private $strTempZipFilename; /**#@-*/ /** * construct the Image_Library object * * download the update archive file, extract the CSV feed file, parse the data * and attempt to download the updated file. * * @author Russell Nash * @access public * @internal Public construct, (globaly accessable) * @internal accessable via the new keyword. * @return (object) new Image_Library object */ public function __construct() { $this->downloadUpdateArchive(); $this->extractArchiveContent(); $arrFeedData = $this->readCsvFile(','); reset($arrFeedData); while($arrCurrent = current($arrFeedData)) { try { $this->downloadImage($arrCurrent[0], $arrCurrent[1], $arrCurrent[3]); } catch (Exception $objException) { echo $objException->getMessage() ."\n"; break; } next($arrFeedData); } } /** * download the update archive and store in a temp location * * @author Russell Nash * @author Midwich IT * @access private * @internal Private method, (internally accessable) * @return (void) */ private function downloadUpdateArchive() { $this->strTempZipFilename = time() . '.zip'; $strZipfileContent = file_get_contents(self::UPDATE_ZIPFILE_URL); $resFile = fopen(self::PATH_TO_TEMP_DIR . "/{$this->strTempZipFilename}", 'w'); fwrite($resFile, $strZipfileContent); fclose($resFile); } /** * extract the update CSV feed file * * @author Russell Nash * @author Midwich IT * @access private * @internal Private method, (internally accessable) * @return (void) */ private function extractArchiveContent() { chdir(self::PATH_TO_TEMP_DIR); shell_exec(self::UNZIP_COMMAND . $this->strTempZipFilename); unlink($this->strTempZipFilename); } /** * read the data from the csv file and convert to an array * * @author Russell Nash * @author Midwich IT * @access private * @internal Private method, (internally accessable) * @param String [$strDelimiter] the text delimiter of the CSV file * @return (array) */ private function readCsvFile($strDelimiter=',') { $arrReturn = array(); $arrCsv = file(self::CSV_FILENAME); reset($arrCsv); while($arrCurrent = current($arrCsv)) { $arrReturn[] = explode($strDelimiter, $arrCurrent); next($arrCsv); } return $arrReturn; } /** * download the PDF file from the CSV feed * * @author Russell Nash * @author Midwich IT * @access private * @internal Private method, (internally accessable) * @param String [$strMidwichPartNumber] the part number to get the PDF for * @param String [$strPdfFilename] the pdf filename * @param Integer [$intPdfFileTime] the modified time of the pdf file * @return (void) */ private function downloadImage($strMidwichPartNumber, $strImageFilename, $intImageFileTime) { $strImageUri = self::PATH_TO_IMAGE_DIR . "/{$strImageFilename}"; if(!is_file($strImageUri) || (filemtime($strImageUri) < $intImageFileTime)) { $strAccountNumber = self::MIDWICH_ACCOUNT_NUMBER; $strPostcode = self::POSTCODE_USED_WITH_MIDWICH; $strDownloadUrl = self::DOWNLOAD_IMAGE_URL . "/{$strAccountNumber}/{$strPostcode}/{$strMidwichPartNumber}"; $strDownloadContent = file_get_contents($strDownloadUrl); if(strpos($strDownloadContent, '') === FALSE) { $resFile = fopen($strImageUri, 'w'); fwrite($resFile, $strDownloadContent); fclose($resFile); } else { throw new Exception('Daily image download limit reached', -1); } chmod($strImageUri, 0755); if($this->blDownloadThumbnails) { $strDownloadUrl .= '/size/thumbnail'; $strImageThumbUri = self::PATH_TO_IMAGE_THUMB_DIR . "/{$strImageFilename}"; $strDownloadContent = file_get_contents($strDownloadUrl); if(strpos($strDownloadContent, '') === FALSE) { $resFile = fopen($strImageThumbUri, 'w'); fwrite($resFile, $strDownloadContent); fclose($resFile); } else { throw new Exception('Daily image download limit reached', -1); } chmod($strImageThumbUri, 0755); } } } } $objSelf = new Image_Library(); ?>[/php]

If anyone could help i would be very grateful Thanks

For reference the original code before i changed anything was (but without line numbers);

[php]1#!/usr/bin/php -ddisplay_errors=on -derror_reporting=E_ALL
2<?php
3/**
4 * Application to process Overnight image retrieval:
5 * simply place this script in your cron to run once a night for every
6 * week day and it will grab all of the missing images in your library.
7 *
8 * Terms & Conditions
9 * This sample code to ease the implimentation of Midwich Data Feeds
10 * into your website is subject to the terms and conditions of the GPL
11* (General Public License). If you do not have a copy it can be
12 * viewed online here: http://www.gnu.org/copyleft/gpl.html
13 *
14 * @author Russell Nash [email protected]
15 * @author Midwich IT [email protected]
16 * @version 1.0.0
17 * @package Image_Library
18 * @subpackage Application
20 * @category Feeds
21 *
22 * @copyright Copyright © 2009 Midwich Ltd, EDI Admin [email protected]
23 * @Created 16/11/2009
24 * @Updated 16/11/2009
25 * @Revision 1.0.0
26 * + 16/11/2009 - Russell Nash
27 * + original application to pplication to process Overnight image retrieval.
28 /
29 /
*
30 * Application to pplication to process Overnight image retrieval:
40 *
50 * @author Russell Nash [email protected]
51* @author Midwich IT [email protected]
52 * @version 1.0.0
53 * @package Image_Library
54 * @subpackage Application
55 * @category Feeds
56 *
57 * @copyright Copyright © 2009 Midwich Ltd, EDI Admin [email protected]
58 * @Created 16/11/2009
59 * @Updated 16/11/2009
60 /
61 class Image_Library {
62 /
* the current version of the script /
63 const VERSION = ‘1.0.0’;
64 /
* your Midwich account number /
65 const MIDWICH_ACCOUNT_NUMBER = ‘0000704130’;
66 /
*
67 * the invoicing postcode used with Midwich
68 * Replace spaces in the post code with %20
69 /
70 const POSTCODE_USED_WITH_MIDWICH = ‘ip22%204yt’;
71 /
*
72 * the path where the temporary files will be stored
73 * Paths must NOT end in /
74 /
75 const PATH_TO_TEMP_DIR = ‘…/img_temp’;
76 /
*
77 * the path where the downloaded image files will be moved to
78* Paths must NOT end in /
79 /
80 const PATH_TO_IMAGE_DIR = ‘…/htdocs/media/image/product’;
81 /
*
82 * the path where the downloaded image thumbnail files will be moved to
83 * Paths must NOT end in /
84 /
85 const PATH_TO_IMAGE_THUMB_DIR = ‘…/htdocs/media/image/thumb’;
86 /
* the URL to download the updated image feed /
87 const UPDATE_ZIPFILE_URL = ‘http://www.midwich.com/download/zip/image_links/false’;
88 /
* the URL to download the updated image file /
89 const DOWNLOAD_IMAGE_URL = ‘http://www.midwich.com/web_services/images’;
90 /
* the URL to download the updated pdf feed /
91 const CSV_FILENAME = ‘image_links.csv’;
92 /
*
93 * the command used to unzip the downloaded archive
94 * Windows users need to invoke an unzip program
95 /
96 const UNZIP_COMMAND = 'unzip -uo ';
97 /#@+
98 * @access protected
99 * @var Boolean
100 /
101 /

102 * flag to download image thumbnails as well as the product image
103 * @see Image_Library::downloadImage()
104 /
105 private $blDownloadThumbnails = TRUE;
106 /
*#@-
/
107 /#@+
108 * @access protected
109 * @var String
110 /
111 /

112 * hold the temporary name for the downloaded archive file
113 * @see Image_Library::downloadUpdateArchive(), Image_Library::extractArchiveContent()
114 /
115 private $strTempZipFilename;
116 /
*#@-
/
117 /
*
118 * construct the Image_Library object
119 *
120 * download the update archive file, extract the CSV feed file, parse the data
121 * and attempt to download the updated file.
122 *
123 * @author Russell Nash [email protected]
124 * @access public
125 * @internal Public construct, (globaly accessable)
126 * @internal accessable via the new keyword.
127 * @return (object) new Image_Library object
128 /
129 public function __construct()
130 {
131 $this->downloadUpdateArchive();
132 $this->extractArchiveContent();
133 $arrFeedData = $this->readCsvFile(’,’);
134 reset($arrFeedData);
135 while($arrCurrent = current($arrFeedData)) {
135 try {
136 $this->downloadImage($arrCurrent[0], $arrCurrent[1], $arrCurrent[3]);
137 } catch (Exception $objException) {
138 echo $objException->getMessage() ."\n";
139 break;
140 }
141 next($arrFeedData);
142 }
143 }
144 /
*
145 * download the update archive and store in a temp location
146 *
147 * @author Russell Nash [email protected]
148 * @author Midwich IT [email protected]
149 * @access private
150 * @internal Private method, (internally accessable)
151 * @return (void)
152 /
153 private function downloadUpdateArchive()
154 {
155 $this->strTempZipFilename = time() . ‘.zip’;
156 $strZipfileContent = file_get_contents(self::UPDATE_ZIPFILE_URL);
157 $resFile = fopen(self::PATH_TO_TEMP_DIR . “/{$this->strTempZipFilename}”, ‘w’);
158 fwrite($resFile, $strZipfileContent);
159 fclose($resFile);
160 }
161 /
*
162 * extract the update CSV feed file
163 *
164 * @author Russell Nash [email protected]
165 * @author Midwich IT [email protected]
166 * @access private
167 * @internal Private method, (internally accessable)
168 * @return (void)
169 /
170 private function extractArchiveContent()
171 {
172 chdir(self::PATH_TO_TEMP_DIR);
173 shell_exec(self::UNZIP_COMMAND . $this->strTempZipFilename);
174 unlink($this->strTempZipFilename);
175 }
176 /
*
177 * read the data from the csv file and convert to an array
178 *
179 * @author Russell Nash [email protected]
180 * @author Midwich IT [email protected]
181 * @access private
182 * @internal Private method, (internally accessable)
183 * @param String [$strDelimiter] the text delimiter of the CSV file
184 * @return (array)
185 /
186 private function readCsvFile($strDelimiter=’,’)
187 {
188 $arrReturn = array();
189 $arrCsv = file(self::CSV_FILENAME);
190 reset($arrCsv);
191 while($arrCurrent = current($arrCsv)) {
192 $arrReturn[] = explode($strDelimiter, $arrCurrent);
193 next($arrCsv);
194 }
195 return $arrReturn;
196 }
197 /
*
198 * download the PDF file from the CSV feed
199 *
200 * @author Russell Nash [email protected]
201 * @author Midwich IT [email protected]
202 * @access private
203 * @internal Private method, (internally accessable)
204 * @param String [$strMidwichPartNumber] the part number to get the PDF for
205 * @param String [$strPdfFilename] the pdf filename
206 * @param Integer [$intPdfFileTime] the modified time of the pdf file
207 * @return (void)
208 */
209 private function downloadImage($strMidwichPartNumber, $strImageFilename, $intImageFileTime)
210 {
211 $strImageUri = self::PATH_TO_IMAGE_DIR . “/{$strImageFilename}”;
212 if(!is_file($strImageUri) || (filemtime($strImageUri) < $intImageFileTime)) {
213 $strAccountNumber = self::MIDWICH_ACCOUNT_NUMBER;
214 $strPostcode = self::POSTCODE_USED_WITH_MIDWICH;
215 $strDownloadUrl = self::DOWNLOAD_IMAGE_URL . “/{$strAccountNumber}/{$strPostcode}/{$strMidwichPartNumber}”;
216 $strDownloadContent = file_get_contents($strDownloadUrl);
217 if(strpos($strDownloadContent, ‘’) === FALSE) {
218 $resFile = fopen($strImageUri, ‘w’);
219 fwrite($resFile, $strDownloadContent);
220 fclose($resFile);
221 } else {
222 throw new Exception(‘Daily image download limit reached’, -1);
223 }
224 chmod($strImageUri, 0755);
225 if($this->blDownloadThumbnails) {
226 $strDownloadUrl .= ‘/size/thumbnail’;
227 $strImageThumbUri = self::PATH_TO_IMAGE_THUMB_DIR . “/{$strImageFilename}”;
228 $strDownloadContent = file_get_contents($strDownloadUrl);
229 if(strpos($strDownloadContent, ‘’) === FALSE) {
230 $resFile = fopen($strImageThumbUri, ‘w’);
231 fwrite($resFile, $strDownloadContent);
232 fclose($resFile);
233 } else {
234 throw new Exception(‘Daily image download limit reached’, -1);
235 }
236 chmod($strImageThumbUri, 0755);
237 }
238 }
239 }
240}
241 $objSelf = new Image_Library();
242 ?>[/php]

No offense, but you would be better off in hiring a programmer, for I highly doubt you’ll find anyone willing to help you out (I could be wrong ???). If you’re a beginner as you say you are, then this script is pay levels above your level.

Or better yet contact the supplier to see if there is any install instructions that came along with the script. I’m surprise there wasn’t a readme doc somewhere that gives you basic instructions on how to set it. Going around willy nilly changing code is diffidently going to break the script, as you can already tell.

it means there’s something wrong with an array, either the data is missing or the array structure is incomplete. Easiest fix is to email the author of the script and see if he can help you.

Sponsor our Newsletter | Privacy Policy | Terms of Service