Kijiji Image Uploading via Javascript

Is this possible? I have a client that needs his ad posted every other day. I’ve automated the process with PHP using cURL and it works great but for text only. If I can figure out how to either include a photo form a link when posting an ad or editing the ad to add the photo after it was just posted.

Unfortunately, I’m not javascript programmer but I’m quite proficient at PHP and using bits and pieces of Javascript to make things work when I need to.

If someone can point me in the right direction I would appreciate it. Here’s the segment of code from Kijiji for the ‘images’ section of their form when you click on the edit page:

	<div id="imageUpload" class="first-field imageUpload">	
		<div class="first-label">				<div style="padding-right:15px;">Images
				</div>
</div>
        <div class="first-input">	
			<input id="Photo_h" name="Photo" value="" type="hidden">
			<a name="Photo"></a>			
			       		<div class="upload-action ">
	       				<div style="width: 110px;" class="flashUpload newButton"><object id="SWFUpload_0" type="application/x-shockwave-flash" data="http://include.classistatic.com/include/e876/c3js/classifieds/rel1/FLASH/swfupload.swf?preventswfcaching=1399922548811" class="swfupload" height="18" width="100"><param name="wmode" value="transparent"><param name="movie" value="http://include.classistatic.com/include/e876/c3js/classifieds/rel1/FLASH/swfupload.swf?preventswfcaching=1399922548811"><param name="quality" value="high"><param name="allowScriptAccess" value="always"><param name="flashvars" value="movieName=SWFUpload_0&amp;uploadURL=http%3A%2F%2Fapi-p.classistatic.com%2Fapi%2Fimage%2Fupload&amp;useQueryString=false&amp;requeueOnError=false&amp;httpSuccess=&amp;assumeSuccessTimeout=0&amp;params=s%3D1C5000%26amp%3Br%3D0%26amp%3Bv%3Dk%26amp%3Bb%3D18%26amp%3Bn%3Dk%26amp%3Ba%3D1%253A69ccc3f402053a81fc5617d15fda366a257dc58636949be5d6f44625de814786&amp;filePostName=u&amp;fileTypes=*.jpg%3B*.png%3B*.bmp%3B*.jpeg%3B*.gif%3B&amp;fileTypesDescription=Images&amp;fileSizeLimit=20%20MB&amp;fileUploadLimit=0&amp;fileQueueLimit=0&amp;debugEnabled=false&amp;buttonImageURL=&amp;buttonWidth=100&amp;buttonHeight=18&amp;buttonText=%3Cspan%20class%3D%22button%22%3ESelect%20Images%3C%2Fspan%3E&amp;buttonTextTopPadding=1&amp;buttonTextLeftPadding=11&amp;buttonTextStyle=.button%20%7B%20font-family%3A%20Helvetica%2C%20Arial%2C%20sans-serif%3B%20font-size%3A%2012pt%3B%20font-weight%3Abold%3B%20%7D%20.buttonSmall%20%7B%20font-size%3A%2010pt%3B%20%7D&amp;buttonAction=-110&amp;buttonDisabled=false&amp;buttonCursor=-2"></object></div>
	       					<div class="photoUpsellWrapper">Get at least twice the number of replies by uploading pictures.</div>
			</div>
					<div class="uploadImgCnt"> 
						<div class="uploadedImageSizeMsg">Max 8 images. File size can be 10 MB per image with max dimension 6000x4000. For bitmap(*.bmp) images, max file size is 4MB.</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
							<div class="uploadedImageBefore">
								<img src="http://imgc.classistatic.com/cps/kjqac/111215/949r1/82926h7_14.jpeg"> 
							</div>
					</div>
			<div id="imageUpload_error">
			</div>
			<!-- MJP -->
		<style type="text/css">
			.flashUpload.newButton{float:left;width:109px;}
		</style>
<script>
		document.write('<script type="text/javascript" language="JavaScript" src="https://secure.kijiji.ca/toronto/s-GetEpsToken"' + '><' + '/script>');
		function processUrlResponse(pic,error,window) {
			if ( window.parent != 'undefined' )
				$(window).remove();
		}
		var errorTexts = {
				'ERROR' :'There was an error uploading your picture. Please check the image size and dimension and try again. If you continue to have issues, you can switch to the <a href=\\"javascript:\\" id=\\"chgToBasicUploader\\" \\>basic image loader</a\\>.',
				'FS' : 'The file size of the picture you attempted to add is too large. Please reduce your picture\\'s file size before adding it again.',
				'FP' : 'You specified a picture file that could not be found on your computer.',
				'ME' : 'There was an error uploading your picture. Please check the image size and dimension and try again. If you continue to have issues, you can switch to the <a href=\\"javascript:\\" id=\\"chgToBasicUploader\\" \\>basic image loader</a\\>.',
				'FC' : 'The content of your picture file is corrupted.',
				'FF' : 'There was a problem with the format of your picture file.',
				'SD' : 'There was a problem connecting to Picture Services.',
				'FLASHDEBUG': 'Flash Upload Debug Info'
				};
		var popupMsg =
				'<CENTER class="modal">' +
					'<TABLE height=210 cellSpacing=0 cellPadding=0 width=240 border=1>' +
					'<TR vAlign=top align=left><TD>' +
					'<TABLE cellSpacing=0 cellPadding=6 width="100%" border=0>' +
					'<TR><TD align=right><div class="closeBtn close">&nbsp;</div></TD></TR>' +
						'<TR align=middle>' +
						    	'<TD><B><FONT face="Verdana, Arial, Helvetica, sans-serif" color=#003399 size=4><I>' +
									'Loading Pictures' +
			            			'</I></FONT><P><FONT face="Verdana, Arial, Helvetica, sans-serif" color=#003399 size=2>' +
									'Your pictures are being sent to our system. Depending on your connection speed and the size of your image files, this might take several minutes. Please wait.' +
						 			'</B></FONT><BR><BR><img src="http://pic.classistatic.com/image/pics/classifieds/busy.gif"/></p></TD></TR></TABLE></TD></TR></TABLE></CENTER>';
	
	var text_additional_style = '';
    
	var imageUpload = {
			id : 'EPS',
			
			enableFlash :true,
			uploadUrl : 'http://api-p.classistatic.com/api/image/upload',
			maxUploaders : 8,
			dataField : 'Photo' ,			
			setId : '1C5000',
			//EPS specific
			thumbnailSizeId : '14',
			originalThumbnailSizeId:'',
			epsVersion : '2',
			defaultSizeId : '18',
				removeText : 'Remove',
			cancelText : 'Cancel',
			retryText : 'Retry upload',
			uploadingText : 'Image uploading',
			pd : 'Enter an image title',
	        flash_button_width : 109,
	        flash_button_height : 18,
	        flash_button_text : '<span class="button">Select Images</span>',
	        flash_button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; font-weight:bold; ' + text_additional_style + '} .buttonSmall { font-size: 10pt; }',
	        flash_button_text_top_padding : 1,
	        flash_button_text_left_padding : 11,
			errorTexts : errorTexts,
			popupMsg : popupMsg
			
			,errorElement: "imageUpload_error"
			,enableAlbumCover: true
			,fieldTip01: 'Get at least twice the number of replies by uploading pictures.'
			,fieldTip02: 'You can change your <span class="mainImageVerb" >main image</span> by selecting a thumbnail below.'
			,selectText: 'Select'
			,suppressAlbumCover: false
	};
	
	$(document).ready(function() {
		
		if ( epsToken != '' ) {
			//uploader.epsToken = epsToken;
			var w = $("#flashLabel").get(0).clientWidth;
			imageUpload.flash_button_width = $("#flashLabel").get(0).clientWidth;
						
			$('#imageUpload').configEpsUploader(imageUpload);
			$('.flashUpload').css('width', function(index) { 
			  return w + 10;
			});
		} else {
			$('#imageUpload').hide();
		};
		//album cover - cloned from existing phototip impl
		var isFlashResizeEnabled = !false;
		if( isFlashResizeEnabled && flashChk.detectFlash(9,9,28)){
			$(".uploadedImageSizeMsg").text('Max 8 images. File size can be 10 MB per image with max dimension 6000x4000. For bitmap(*.bmp) images, max file size is 4MB.');
		};
		// album cover -ie7 positioning, for non-flash uploader
		if (!flashChk.detectFlash(9,9,28)) {
			 if ($.browser.msie ) {
				$('.uploadImgCnt').css('margin-top','25px');
			 } else {
				$('.uploadImgCnt').css('margin-top','0px');
			 }
		}
	});
</script><script type="text/javascript" language="JavaScript" src="https://secure.kijiji.ca/toronto/s-GetEpsToken"></script>
			<noscript><div class="help">Please enable JavaScript to add pictures.</div></noscript>
		</div>
	</div>
<div id="flashLabel">Select Images</div>
			</div>

If it helps - I’ll I’m trying to do is simulate the following two actions when posting a new ad to Kijiji:

  1. Click on Select Images
  2. Upload an image