Hi,
I was wondering, if it possible to upload an image from my server to a different server.
Example: –
Someone goes to my website, they enter the details. I then put there details in my database and then I have an image file upload onto another server. So somehow i need to call the script (which is below) from another server.
I cant however locate the form to this upload page on the other server as i need to put things into my database, I know i cant upload the image from my server to there because of the permisions, which is why i thought of puttin an upload function on the other server for me to call. The thing is im not sure how to call this function and pass over the image to it that i have just uploaded?
Thanks
Adam
[code=php]
function uploadImg() {
// Sort out the image
$size = 125; // the thumbnail height
$filedir = CUSTOMERS_HTTP_SERVER . CUSTOMERS_DIR_WS_HTTP_CATALOG . CUSTOMERS_DIR_WS_CATALOG_IMAGES; // the directory for the original image
$thumbdir = CUSTOMERS_HTTP_SERVER . CUSTOMERS_DIR_WS_HTTP_CATALOG . CUSTOMERS_DIR_WS_CATALOG_IMAGES; // the directory for the thumbnail image
$maxfile = ‘2000000’;
$mode = ‘0666’;
$ImageExt = explode(“.”,$_FILES[‘ProductImage’][‘name’]);
$ImageExt = ‘.’ . $ImageExt[1];
$userfile_name_F = ($GetNewProduct_ID + CUSTOMERS_PID_OFFSET) . ‘_F’ . $ImageExt;
$userfile_name_T = ($GetNewProduct_ID + CUSTOMERS_PID_OFFSET) . ‘_T’ . $ImageExt;
$userfile_name = ($GetNewProduct_ID + CUSTOMERS_PID_OFFSET) . $ImageExt;
$userfile_tmp = $_FILES[‘ProductImage’][‘tmp_name’];
$userfile_size = $_FILES[‘ProductImage’][‘size’];
$userfile_type = $_FILES[‘ProductImage’][‘type’];
if (isset($_FILES[‘ProductImage’][‘name’])) {
$prod_img = $filedir . $userfile_name_F;
$prod_img_thumb = $thumbdir . $userfile_name_T;
move_uploaded_file($userfile_tmp, $prod_img);
chmod($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size) {
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die(‘Problem In Creating image’);
$srcimg=ImageCreateFromJPEG($prod_img) or die(‘Problem In opening Source Image’);
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die(‘Problem In resizing’);
ImageJPEG($destimg,$prod_img_thumb,90) or die(‘Problem In saving’);
imagedestroy($destimg);
}
}