andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Yet another Upload-Crop-View-Save Question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas
View previous topic :: View next topic  
Author Message
Sandbird
Newbie


Joined: 03 Sep 2005
Posts: 2

PostPosted: Sat Sep 03, 2005 9:42 am    Post subject: Yet another Upload-Crop-View-Save Question Reply with quote

Hi Andy, and everone else.

I am making a website that i want my users to be able to create "groups" that they can upload a small picture as the group's logo. The picture has to be a certain width and height though so i want them when they upload the picture to select the cropped part of the picture.Then click submit and the picture will be saved in a folder.
The thing is that i tried every upload and crop code in the forum but i couldnt get passed the upload step to load the picture i uploaded in the crop.php page. The header is all good...it should work but its not!!!
I know how to save the picture i just need the code like exactly in the demo page you showed....A person uploads the photo, it takes him to the cropping page and then either shows the photo or saves it.
my upload function is like this
Code:

<?php

    define('BASE_DIR',  $_SERVER['DOCUMENT_ROOT'] . '/');
    define('IMAGE_DIR', BASE_DIR . 'uploads');

    if (!isset($_FILES) || empty($_FILES)) {
        echo '<form action="" method="post" enctype="multipart/form-data">';
        echo 'Select your image type to upload<br />';
        echo '<input type="file" name="image"> <input type="submit" value="upload"><br />';
        echo '</form>';
    } else {
        $filename = str_replace(' ', '_', preg_replace('/\s+/', ' ', preg_replace('/[^a-z0-9-_ ]/i', '', $_FILES['image']['name'])));
        if (move_uploaded_file($_FILES['image']['tmp_name'], IMAGE_DIR . $filename)) {
            // do you processing on the file here
            // IMAGE_DIR . $filename
        } else {
            echo 'There was an error uploading that file.';
            print_r($_FILES);
        }
    }

?>


and the crop page :

Code:

<?php

    require_once('config.php');
    require_once('class.cropinterface.php');
    $ci =& new cropInterface();
     
    if (isset($_GET['file']) && isset($_GET['sx']))
    {
        $ci->loadImage($_GET['file']);
        $ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']);
        $ci->saveImage(CROP_DIR . $_GET['file']);
        header('Content-type: image/jpeg');
        $ci->showImage('jpg', 90);
        exit;
    }

?>
<html>

<head>
    <style type="text/css">
        body, td, p
        {
            font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
            font-size: 10px;
        }
         
        #submit
        {
            font-size: 10px;
            font-family: "MS Sans Serif", Geneva, sans-serif;
            height: 23px;
            background-color: #D4D0C8;
            border: 0px;
            padding: 3px,5px,3px,5px;
            width: 100%;
        }
    </style>
</head>
<body>

<?php

        $ci->loadInterface(UPLOAD_DIR . $_GET['file']);
        $ci->loadJavaScript();
?>

</body>
</html>


when i run the crop.php by itself it says:
The file 'c:\wamp\www/uploaded/' cannot be found.

( i run wamp server in windows XP btw)

oh and something else.....the upload does upload the photo but with a filename without any seperating (.) its like mypicturejpg.
Pleeeeeease give me some hints....or code :p
I know this question has been asked 1000 times and i did read all of them...but please tell me what am i doing wrong.
Thanks again and sorry for the trouble. (Maybe a step-by-step sticky will solve you many people asking this silly question :p)
-mario
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Sep 07, 2005 3:38 am    Post subject: Reply with quote

Hi Sandbird, and welcome to the board!

The reason you're getting 'mypicturejpg' is because of the regular expression being used. This line:

Code:
$filename = str_replace(' ', '_', preg_replace('/\s+/', ' ', preg_replace('/[^a-z0-9-_ ]/i', '', $_FILES['image']['name'])));


should be:

Code:
$filename = str_replace(' ', '_', preg_replace('/\s+/', ' ', preg_replace('/[^a-z0-9-_\.]/i', '', $_FILES['image']['name'])));


It's probably uploading correctly, it's just not copying it to where you expect. Take these three lines in the code:

PHP:
<?php define('BASE_DIR',  $_SERVER['DOCUMENT_ROOT'] . '/');
    
define('IMAGE_DIR'BASE_DIR 'uploads');

     
//...

     
if (move_uploaded_file($_FILES['image']['tmp_name'], IMAGE_DIR $filename)) { ?>


What you're actually saying there is to move your uploaded file to the location (imagine that your document root is /home/www) /home/www/uploadsmypicture.jpg, because you're missing the trailing slash between the uploads directory and the filename. Simple solution:

Code:
define('IMAGE_DIR', BASE_DIR . 'uploads/');


Now for the crop problem... I'm assuming you have set 'UPLOAD_DIR' and 'CROP_DIR' to the proper locations. This line:

Code:
$ci->loadInterface(UPLOAD_DIR . $_GET['file']);


requires that you have the name of the file passed along in the query string via a GET request. Do you? If $_GET['file'] is empty (ie, you don't have something like crop.php?file=mypic.jpg as an address) the that would account for the loading error you're getting. Try passing along the file name, or hard coding it in the script for testing purposes, such as:

Code:
$ci->loadInterface(UPLOAD_DIR . 'mypic.jpg');


Hope that helps!

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Sandbird
Newbie


Joined: 03 Sep 2005
Posts: 2

PostPosted: Sat Sep 24, 2005 8:52 am    Post subject: Reply with quote

Thanks man, i will check it out Smile
Sorry for the late reply....
Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group