Jump to content

photo editor API intergration


glow

Recommended Posts

Hi everyone

 

My question might be a real simple one but I'm afraid that I'm very new to php.

 

I',ll try to explain briefly what i'm trying to do.

 

I have this community flash image gallery script currently it just basically uploads images. I'd like to make it so the user has the option to edit the images prior to upload.

 

So I found this "Fotoflexer" (http://fotoflexer.com/api.php) image editor API wish promises to be really simple to install, but I've stumbled upon a problem It is asking to simply fill in the image to be edited url and the url that will be called when the user is finished editing.

 

Now all of my logic tells me that the URL of the image to be edited is unknown being that is being upload by the users from who knows where.

 

this is the code for the script

 

<?php

// Parse paramters to get Image and thumbnail urls
$image = $_GET['image'];
$thumb = $_GET['thumb'];

// Verify that the URL begins with "http://fotos.fotoflexer.com"
// This step is used to ensure that the image is in authentic

if (strpos($image, "http://fotos.fotoflexer.com") != 0){
  //Handle the error:
  echo "Invalid Origin";
  exit;
}
if (strpos($thumb, "http://fotos.fotoflexer.com") != 0){
  //Handle the error:
  echo "Invalid Origin";
  exit;
}

// Verify that the file is an image
$headers = get_headers($image, 1);
$content_type = explode("/", $header[Content-Type]);
if ($content_type[0] != "image"){
//Handle the error
echo "Invalid File Type";
exit;
}
$headers = get_headers($thumb, 1);
$content_type = explode("/", $header[Content-Type]);
if ($content_type[0] != "image"){
//Handle the error
echo "Invalid File Type";
exit;
}

// Grab the image type (png or jpeg)
$file_type = $content_type[1];

// Set the local file path for the image and thumbnail
$image_path = "/path/to/images/image_name." . $file_type;
$thumb_path = "/path/to/thumbnails/thumbnail_name." . $file_type;

// Image source and content have been verified, and a location has been set.
// Now copy the images to the local server.
copy($image,$image_path);
copy($thumb,$thumb_path);

// Both image and thumb are on your server at the location specified!

// Optional:
// if this is is an intermediate page, you can now setup your server state
// and redirect

/*
header("Location:Path/AnotherPage.html");
*/

?>

 

I just don't get how I can implement this a multiuser enviroment when it is asking for an image specific location, there are many users with many image folders and new ones always created.

 

anyways if anyone could please help me with this this is my current image upload php code.

 

 

0);
else if (strpos($_REQUEST[del],$upload_dir) === false);
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print "";
}
}
else if ($_FILES['userfile']) {

$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url, $image, $upcheck);

print "";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";

/
* List Files
/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "".$file."";
if ($DELETABLE)
$filelist .= " x";
$filelist .= " ".date("d-m H:i", filemtime($upload_dir.$file))
."";
$filelist .="";
}
}


// Delete File

if ($delete_file)
{

if ($upcheck == "ok"){

$d = $image;

unlink ("$upload_url$d");

echo "File Deleted!";
exit;
}
}



function do_upload($upload_dir, $upload_url, $image, $upcheck) {



if ($upcheck == "ok"){

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\","",$file_name);
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$image;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}

$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name uploaded successfully." :
"Somthing is wrong with uploading a file.";
echo "UPLOAD WAS SUCCESSFUL!Click Here to close this window








";
exit;
return $message;

}


}




if ($upcheck == "ok"){


?>








Upload File

<input type="hidden" name="image" value="">
<INPUT TYPE="hidden" name="userid" value="">
<INPUT TYPE="hidden" name="password" value="">

                   

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.