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 to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having error in upload-procedure

    Hi all, since the forums of the Dutch coding-community (at which I'm an active member) generally "aren't that good".. I'll try to get help elsewhere. Great to see that more of these well-populated forums exist.

    Anyway, let's get to business.

    I'm creating a script, which should upload a file while an URL has been given to the file. And actually everything goes ok, until I go copying the file to my server. And as it isn't a superscript (probably, I think), it's more or less a project to learn and understand a lot about file-handling in PHP.

    What's happening?
    Getting an error, its output is as followed:
    Warning: copy(./avatars/ava1pl.jpg) [function.copy]: failed to open stream: Permission denied in /home/poison/domains/poisonlog.net/public_html/cp_check.php on line 100

    And at first, I thought it might have been the permissions. So I turned the CHMOD of my map to maximum (and totally unnecessarily) to 0777. But that didn't work..
    So I went checking if Safemode was on, but... Nope, it wasn't.


    I've been working at this script as of yesterday, and actually it's getting really boring and frustating that I can't get further than 3 lines each hour, and most of them are empty lines...


    My code:
    PHP Code:
        if(isset($_POST['avatar']) && !empty($_POST['avatar']) && $_POST['avatar'] != $result['avatar']){
            
    $allowed_filetypes "jpg|jpeg|jfif|jpe|gif|png";
            if(!
    preg_match('/^(http:\/\/)?([\w\-\.]+)\:?([0-9]*)\/([^ \?&=\#\"\n\r\t<]*?(\.('.$allowed_filetypes.')))$/',$_POST['avatar'],$farr)){
                
    $input_error['Avatar URL'] = "De avatar voldoet niet aan de eisen (alleen ".str_replace("|",", ",$allowed_filetypes)." toegestaan).";
            }else{
                
    $bget '/' $farr[4];
                
    $port = (!empty($farr[3])) ? $farr[3] : 80;
                if(!(
    $fp = @fsockopen($farr[2], $port$errno$errstr))){
                    
    $input_error['Avatar openen'] = "De avatar kon niet geopend worden. Controleer de opgegeven URL (".$_POST['avatar'].").";
                }else{
                    
    fputs($fp"GET $bget HTTP/1.1\r\n");
                    
    fputs($fp"HOST: " $farr[2] . "\r\n");
                    
    fputs($fp"Connection: close\r\n\r\n");

                    
    stream_set_timeout($fp,10);

                    
    $fdata '';
                    while(!
    feof($fp)){
                        
    $fdata .= fread($fp,1024*50);
                    }
                    
    fclose($fp);

                    if(!
    preg_match('#Content-Length\: ([0-9]+)[^ /][\s]+#i'$fdata$fsizearr) || !preg_match('#Content-Type\: image/[x\-]*([a-z]+)[\s]+#i'$fdata$ftypearr)){
                        
    $input_error['Avatar toegang'] = "Het programma had problemen met het uitlezen van het avatar-bestand. Mogelijk wordt dit veroorzaakt door een kapot bestand.";
                    }else{
                        
    $max_avatar_size = (1024*$avatar_max_sizekb);
                        
    $filesize $fsizearr[1];
                        
    $filetype $ftypearr[1];

                        if(
    $filesize $max_avatar_size){
                            
    $input_error['Avatar grootte'] = "Je avatar mag niet groter zijn dan ".($max_avatar_size/1024)." KB. Uw avatar is ".round($filesize/1024)." KB.";
                        }else{
                            
                            
    $fdata substr($fdata,(strlen($fdata)-$filesize),$filesize);
                            
    $extension $farr[6];

                            
    $path './avatars/';
                            
    $tmpfname tempnam(realpath($path),'avapl');

                            
    $tmpfopen fopen($tmpfname,"w");
                            
    $tmpfwrite fwrite($tmpfopen,$fdata,$filesize);

                            
    fclose($tmpfopen);

                            list(
    $width,$height,$type) = getimagesize($tmpfname);
                            echo 
    "Bestandsgrootte: ".$filesize." Bytes<br />";
                            echo 
    "Bestandstype: ".$filetype."<br />";
                            echo 
    "Bestandsbreedte: ".$width."<br />";
                            echo 
    "Bestandshoogte: ".$height."<br />";

                            if(
    $tmpfwrite $filesize){
                                
    $input_error['Bestand schrijven'] = "Het bestand kon niet worden geschreven.";
                                @
    unlink($tmpfname);
                            }else{
                                if(
    $width>&& $height>&& $width<=$avatar_max_width && $height<=$avatar_max_height){
                                    
    $imagename "ava".$_SESSION['user_id']."pl.".$extension;
                                    if(!empty(
    $result['avatar'])){
                                        
    $query "UPDATE users SET avatar='' WHERE user_id='".$_SESSION['user_id']."'";
                                        
    mysql_query($query) or $error .= Error("00035","Kan avatar-gegevens niet updaten.");
                                    }
                                    
    copy($tmpfname,$path.$imagename);
                                    
    unlink($tmpfname);
                                }
                            }
                        }
                    }
                }
            }
        }else{
            if(empty(
    $_POST['avatar'])){
                
    $avatar "";
            }else{
                
    $avatar $result['avatar'];
            }
        } 

    I don't think you will be distracted too much by the few Dutch sentences as errors or output, since I use English variables.
    If you need any clarification to a variable or text or anything, please ask. I'm getting totally desperate with this code.
    Last edited by w_oute_r; 08-05-2007 at 11:31 PM. Reason: Found an error in my text!

  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    "So I turned the CHMOD of my map to maximum (and totally unnecessarily) to 0777. But that didn't work.."

    ./avatars/ is the folder that requires write perms. What are you referring to by "map" in the above statement? Just change ./avatars to 777.
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh my, it works now.. Very, very many thanks

    (I really thought I had it on 777 before)


  •  

    Posting Permissions

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