Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problem using @move_uploaded_file($tmp_file, $directory);

    hey i have completed a site which is named http://www.atneshop.com/ and running well and i used there @move_uploaded_file($tmp_file, $directory) for moving file to my $directory

    now i want to develop another site where i would have use same script for uploading and it is fine in my offline server (wamp)

    but i test it in online then i got this error:
    There was an error moving the uploaded file.

    i have attached my code snippet. please check it

    PHP Code:
    function UploadImages($file,$get_file_size,$tmp_file,$directory,$directory_main// for profile
    {
        global 
    $chk_img;
        
    $file_type = array("gif","png","jpg","jpeg","GIF","PNG","JPG","JPEG");
        
    $file_info=end(explode("."$file));

        
    //echo 'tmp = '.$tmp_file.'<br />';
        //echo "Size: " . $get_file_size . " bytes<br />";

        
    if($file!='')
        {
            if(empty(
    $tmp_file) && $get_file_size==0// Large File Size
            
    {
                
    $msg='Check File Size!!';
            }
            
    /*else if(file_exists($directory_main)) // When File Exists
            {
                $msg='File Already Exists!!';
            }*/
            
    else
            {
                if (
    in_array($file_info,$file_type)) // When Valid File Type
                
    {
                    
    $result = @move_uploaded_file($tmp_file$directory);

                    if(empty(
    $result)) // when can't upload file
                    
    {
                        
    $msg "There was an error moving the uploaded file.";
                    }
                    else 
                    {
                        
    $mode '0777';
                        
    chmod ($directoryoctdec($mode));
                        
    $msg='Information has been saved Successfully!!';
                        
    $chk_img=1;

                        
    // Resize Checking
                        
    list ($width,$height,$type) = @getimagesize($directory);

                        
    $max_width=90;
                        
    $max_height=90;

                        if( (
    $height <=$max_height)&&($width <=$max_width) )
                        {
                            
    $new_width $width;
                            
    $new_height $height;
                        }
                        else if( (
    $height <$max_height)&&($width >$max_width) )
                        {
                            
    $new_width $max_width;
                            
    $new_height =(int)($max_width* ($height/$width));
                        }
                        else if( (
    $height >$max_height)&&($width <$max_width) )
                        {
                            
    $new_height =$max_height;
                            
    $new_width = (int)($max_height*($width/$height));
                        }
                        else if ( (
    $height >$max_height)&&($width >$max_width) )
                        {
                            
    $RH=$height/$max_height;
                            
    $RW=$width/$max_width;

                            if(
    $RH>$RW)
                            {
                                
    $new_height =$max_height;
                                
    $new_width = (int)($max_height*($width/$height));
                            }
                            else if(
    $RH<$RW)
                            {
                                
    $new_width $max_width;
                                
    $new_height =(int)($max_width* ($height/$width));
                            }
                            else
                            {
                                
    $new_width $max_width;
                                
    $new_height $max_height;
                            }
                        }
                        
    //echo '<br>$width= '.$width.'  $height='.$height;
                        //echo '<br>$new_width= '.$new_width.'  $new_height='.$new_height;
                        
                        
    if(($new_width==$width) &&  ($new_height==$new_height)) // when resize not needed
                        
    {
                            
    //echo '<br>Yes';
                            
    rename($directory,$directory_main) or die('can not rename');
                        }
                        else 
    // Resize
                        
    {
                            
    /* echo '<br>$new_width= '.$new_width.'  $new_height='.$new_height; */
                            
    $destimg=imagecreatetruecolor($new_width,$new_height) or die('Problem In Creating image');
                            switch (
    $type)
                            {
                                case 
    1:
                                        
    $srcimg=imagecreatefromgif($directory) or die('Problem In opening Source Image');

                                        
    // keeping transparency
                                        
    $transparent_index imagecolortransparent($srcimg);

                                        if (
    $transparent_index >= 0)
                                        {
                                            
    imagepalettecopy($srcimg$destimg);
                                            
    imagefill($destimg00$transparent_index);
                                            
    imagecolortransparent($destimg$transparent_index);
                                            
    imagetruecolortopalette($destimgtrue256);
                                        }
                                        
    // keeping transparency

                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagegif($destimg,$directory_main,100) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                                        break;
                                case 
    2:
                                        
    $srcimg=imagecreatefromjpeg($directory) or die('Problem In opening Source Image');
                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagejpeg($destimg,$directory_main,100) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                                        break;
                                case 
    3:
                                        
    $srcimg=imagecreatefrompng($directory) or die('Problem In opening Source Image');

                                        
    // keeping transparency
                                        
    imagealphablending($destimgfalse);
                                        
    imagesavealpha($destimg,true);
                                        
    $transparent imagecolorallocatealpha($destimg255255255127);
                                        
    imagefilledrectangle($destimg00$new_width$new_height$transparent);
                                        
    // keeping transparency

                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagepng($destimg,$directory_main,9) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                            }
                        }                           
                    }
                }
                else
                {
                    
    $msg='Invalid File Type!!';
                }
            }
        }
        return 
    $msg;
    }

            
    //-------------------- Image Upload----------------------------//   
            
    //-------------------- Image Upload----------------------------//
    function UploadImages1($file,$get_file_size,$tmp_file,$directory,$directory_main// for profile
    {
        global 
    $chk_img1;
        
    $file_type = array("gif","png","jpg","jpeg","GIF","PNG","JPG","JPEG");
        
    $file_info=end(explode("."$file));

        
    //echo 'tmp = '.$tmp_file.'<br />';
        //echo "Size: " . $get_file_size . " bytes<br />";

        
    if($file!='')
        {
            if(empty(
    $tmp_file) && $get_file_size==0// Large File Size
            
    {
                
    $msg='Check File Size!!';
            }
            
    /*else if(file_exists($directory_main)) // When File Exists
            {
                $msg='File Already Exists!!';
            }*/
            
    else
            {
                if (
    in_array($file_info,$file_type)) // When Valid File Type
                
    {
                    
    $result = @move_uploaded_file($tmp_file$directory);

                    if(empty(
    $result)) // when can't upload file
                    
    {
                        
    $msg "There was an error moving the uploaded file.";
                    }
                    else 
                    {
                        
    $mode '0777';
                        
    chmod ($directoryoctdec($mode));
                        
    $msg='Information has been saved Successfully!!';
                        
    $chk_img1=1;

                        
    // Resize Checking
                        
    list ($width,$height,$type) = @getimagesize($directory);

                        
    $max_width=800;
                        
    $max_height=600;

                        if( (
    $height <=$max_height)&&($width <=$max_width) )
                        {
                            
    $new_width $width;
                            
    $new_height $height;
                        }
                        else if( (
    $height <$max_height)&&($width >$max_width) )
                        {
                            
    $new_width $max_width;
                            
    $new_height =(int)($max_width* ($height/$width));
                        }
                        else if( (
    $height >$max_height)&&($width <$max_width) )
                        {
                            
    $new_height =$max_height;
                            
    $new_width = (int)($max_height*($width/$height));
                        }
                        else if ( (
    $height >$max_height)&&($width >$max_width) )
                        {
                            
    $RH=$height/$max_height;
                            
    $RW=$width/$max_width;

                            if(
    $RH>$RW)
                            {
                                
    $new_height =$max_height;
                                
    $new_width = (int)($max_height*($width/$height));
                            }
                            else if(
    $RH<$RW)
                            {
                                
    $new_width $max_width;
                                
    $new_height =(int)($max_width* ($height/$width));
                            }
                            else
                            {
                                
    $new_width $max_width;
                                
    $new_height $max_height;
                            }
                        }
                        
    //echo '<br>$width= '.$width.'  $height='.$height;
                        //echo '<br>$new_width= '.$new_width.'  $new_height='.$new_height;
                        
                        
    if(($new_width==$width) &&  ($new_height==$new_height)) // when resize not needed
                        
    {
                            
    //echo '<br>Yes';
                            
    rename($directory,$directory_main) or die('can not rename');
                        }
                        else 
    // Resize
                        
    {
                            
    /* echo '<br>$new_width= '.$new_width.'  $new_height='.$new_height; */
                            
    $destimg=imagecreatetruecolor($new_width,$new_height) or die('Problem In Creating image');
                            switch (
    $type)
                            {
                                case 
    1:
                                        
    $srcimg=imagecreatefromgif($directory) or die('Problem In opening Source Image');

                                        
    // keeping transparency
                                        
    $transparent_index imagecolortransparent($srcimg);

                                        if (
    $transparent_index >= 0)
                                        {
                                            
    imagepalettecopy($srcimg$destimg);
                                            
    imagefill($destimg00$transparent_index);
                                            
    imagecolortransparent($destimg$transparent_index);
                                            
    imagetruecolortopalette($destimgtrue256);
                                        }
                                        
    // keeping transparency

                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagegif($destimg,$directory_main,100) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                                        break;
                                case 
    2:
                                        
    $srcimg=imagecreatefromjpeg($directory) or die('Problem In opening Source Image');
                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagejpeg($destimg,$directory_main,100) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                                        break;
                                case 
    3:
                                        
    $srcimg=imagecreatefrompng($directory) or die('Problem In opening Source Image');

                                        
    // keeping transparency
                                        
    imagealphablending($destimgfalse);
                                        
    imagesavealpha($destimg,true);
                                        
    $transparent imagecolorallocatealpha($destimg255255255127);
                                        
    imagefilledrectangle($destimg00$new_width$new_height$transparent);
                                        
    // keeping transparency

                                        
    imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,$width,$height);
                                        
    imagepng($destimg,$directory_main,9) or die('Problem In saving');
                                        
    imagedestroy($destimg);
                                        
    unlink($directory);
                            }
                        }                           
                    }
                }
                else
                {
                    
    $msg='Invalid File Type!!';
                }
            }
        }
        return 
    $msg;
    }

    //-------------------- Image Upload----------------------------//       
    ?> 

  • #2
    New Coder
    Join Date
    Dec 2008
    Location
    India
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please check upload_tmp_dir must have your local folder path in php.ini
    Regards
    InnovateWebs
    "Committed to Quality "
    http://www.innovatewebs.com

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by innovatewebs View Post
    Please check upload_tmp_dir must have your local folder path in php.ini

    i m using parallels plesk control panel
    please tell me where woild i get php.ini

    or in which folder i would keep my php.ini file in my domain channelishop.com

    please it is urgent for me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •