TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Uploading problem (http://www.talkphp.com/absolute-beginners/3592-uploading-problem.html)

Tanax 11-11-2008 06:15 PM

Uploading problem
 
Hi, why does this exception get thrown?

PHP Code:

if(!move_uploaded_file($_FILES[$this->form_inputName]['tmp_name'], $this->image_tmpPath $this->file_name))
        {
                    
            throw new 
Exception('An error occured when uploading your file.');
                    
        } 

I mean, am I doing something wrong? Or is it just my variables that probably isn't correct?

Edit:
Got this now:

Code:

Warning: move_uploaded_file(images/2/tmp/23aede79f5b4c7aa2a97d7af38023893.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\test\Upload.php on line 142

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpABF.tmp' to 'images/2/tmp/23aede79f5b4c7aa2a97d7af38023893.jpg' in C:\wamp\www\test\Upload.php on line 142


Tanax 11-11-2008 07:16 PM

Nevermind! I solved that. Now it's just the thumbnail part that doesn't work:

php Code:
private function createThumb()
    {
       
        switch($_FILES[$this->form_inputName]['type'])
        {
           
            case 'image/jpeg':
               
                $srcimage = imagecreatefromjpeg($this->image_bigPath . $this->file_name);
                break;

            case 'image/gif':

                $srcimage = imagecreatefromgif($this->image_bigPath . $this->file_name);
                break;

            case 'image/png':
               
                $srcimage = imagecreatefrompng($this->image_bigPath . $this->file_name);
                break;
           
            default:
               
                $srcimage = imagecreatefromjpeg($this->image_bigPath . $this->file_name);
               
        }
       

        $srcimagex = imagesx($srcimage);
        $srcimagey = imagesy($srcimage);
        if($srcimagex > $this->thumb_width || $srcimagey > $this->thumb_height)
        {

            if($srcimagex > $srcimagey) $ratio = $this->thumb_width / $srcimagex;
            elseif($srcimagex < $srcimagey) $ratio = $this->thumb_height / $srcimagex;
            else $ratio = (($this->thumb_width + $this->thumb_height) / 2) / $srcimagey;

            $thumbwidth = $srcimagex * $ratio;
            $thumbheight = $srcimagey * $ratio;
           
            $thumbnail = imagecreatetruecolor($thumbwidth, $thumbheight);
            imagecopyresampled($thumbnail, $srcimage, 0, 0, 0, 0, $thumbwidth, $thumbheight, $srcimagex, $srcimagey);
            $success = imagejpeg($thumbnail, $this->image_thuPath . $this->file_name, 75);
           
            if($success)
            {
               
                $this->thumb_creation = 1;
                unlink($this->image_thuPath . $this->file_name);
               
            }
           
            else throw new Exception('Thumbnail creation did not work.');         

        }
       
    }

Tanax 11-12-2008 09:02 AM

Nevermind again xD I solved it thanks to Eyedentify :-)

EyeDentify 11-12-2008 10:58 AM

@Tanax.

Iīm just glad i could help.

I know how it is, Sometimes you donīt see your misstakes clearly if you have starred at a code snippet for a while. Then itīs good to have someone else to have a look.

And to clearify, the error seems to have been the unlink() functions strategic placement :) it caused the Thumbnail to get deleted. :)

Tanax 11-12-2008 11:08 AM

Hehe yea, I know xD It got deleted right after it was created :P I suck >.< hehe


All times are GMT. The time now is 05:33 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0