Uploading file problem

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

This is really beginning to pee me off. I've being working on this for about 2 hours :evil:

I have a form that I'm using to upload files from my drive to my site (For the avatar feature). I got the class to do that from PHPCLASSES.ORG.

The part that is annoying me is:
Code: [ Select ]
File: <input type="file" name="hd_avatar" id="hda" size="25" />

And the PHP for that is: (Quite long)
PHP Code: [ Select ]
<?php
class ucp {
   
    private $errors = 0;
   
    /*
     * function __construct( void )
     *
     * The construct function for the UCP class
     */
   
    function __construct()
    {
        if(!isset($_SESSION['user']))
        {
            header("LOCATION: index.php");
        }
    }
   
    /*
     * function submit_account( string $email, string $conemail, string $pass, string $conpass, string $ola, string $hda, string $web, string $ctitle, string $msn, string $signature, string $allow_email, string $show_email, string $contact_choice)
     *      @string $email - User's email
     *      @string $conemail -  Same user's email
     *      @string $pass - Users password
     *      @string $conpass -  User's password retyped for confirmation
     *      @string $ola - User's avatar local to the website
     *      @string $hda - User's avatar from user's computer
     *      @string $web - User's website
     *      @string $ctitle - User's custom title
     *      @string $msn - User's MSN
     *      @string $signature - User's signature
     *      @string $allow_email - User's choice wether or not they want to get email from other users
     *      @string $show_email - User's choice wether they want their email to be securely shown
     *      @string $contact_choice - User's contact choice. Possible values:
     *                  1: PM
     *                  2: Email
     *                  3: Either
     *      
     * Basically a construct function for the account form
     */
   
    function submit_account($email, $conemail, $pass, $conpass, $ola, $hd_avatar, $web, $ctitle, $msn, $signature, $allow_email, $show_email, $contact_choice)
    {
        global $db;
       
        // Initiating the return array
        $return = array();
       
        $reg_var = $db->_get_('email', USERS, array('UID' => $_SESSION['user']));
       
        if($email != $reg_var)
        {
            $return[] = $this->update_email($_SESSION['user'], $email, $conemail);
        }
       
        if(!empty($pass))
        {
            $return[] = $this->update_password($_SESSION['user'], $pass, $conpass);
        }
       
        $reg_var = $db->_get_('avatar', USERS, array('UID' => $_SESSION['user']));
        var_dump($_FILES['hd_avatar']);
        if(sizeof($_FILES['hd_avatar'][0]) > 0)
        {
            $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
        }
       
        $reg_var = $db->_get_('website', USERS, array('UID' => $_SESSION['user']));
       
        if($web != $reg_var)
        {
            $return[] = $this->update_website($_SESSION['user'], $web);
        }
       
        $reg_var = $db->_get_('custom_title', USERS, array('UID' => $_SESSION['user']));
       
        if($ctitle != $reg_var)
        {
            $return[] = $this->update_custom_title($_SESSION['user'], $ctitle);
        }
       
        $reg_var = $db->_get_('MSN', USERS, array('UID' => $_SESSION['user']));
       
        if($msn != $reg_var)
        {
            $return[] = $this->update_msn($_SESSION['user'], $msn);
        }
       
        $reg_var = $db->_get_('signature', USERS, array('UID' => $_SESSION['user']));
       
        if($signature != $reg_var)
        {
            $return[] = $this->update_signature($_SESSION['user'], $signature);
        }
       
        if($allow_email != 0)
        {
            $return[] = $this->allow_email($_SESSION['user'], $allow_email);
        }
       
        if($show_email != 0)
        {
            $return[] = $this->show_email($_SESSION['user'], $show_email);
        }
       
        if($contact_choice != 0)
        {
            $return[] = $this->contact_choice($_SESSION['user'], $contact_choice);
        }
       
        // Returning the results
        if(sizeof($return) > 0)
        {
            if($this->errors > 0)
            {
                $type1 = ($errors > 1) ? "were" : 'was';
                $type2 = ($errors > 1) ? "'s" : null;
                $text = "<p>There $type1 $errors mistake$type2 in the form.</p>\n";
            }
            else
            {
                $text = "<p>Your form was successfully submitted and your profile was edited.</p>\n";
            }
            $text .= "                <ul>\n";
            foreach($return as $return_val)
            {
                $text .= "                    <li>$return_val</li>\n";
            }
            $text .= "                </ul>\n";
           
            return trim($text);
        }
        else
        {
            return "<p>No changes were made.</p>\n";
        }
    }
   
    function update_email($uid, $email, $conemail)
    {
        global $db, $regex;
       
        if($email != $conemail)
        {
            $this->errors +1;
            return "Your email does not match your confirmation email.";
            break;
        }
       
        if(!preg_match($regex['EMAIL'], $email) || !preg_match($regex['EMAIL'], $conemail))
        {
            $this->errors +1;
            return "Your email are of incorrect type.";
            break;
        }
       
        $sql = array(
            'email' => $email,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "Email updated successfully";
        }
    }
   
    function update_password($uid, $pass, $conpass)
    {
        global $db;
       
        if($pass != $conpass)
        {
            $this->errors +1;
            return "Your password does not match your confirmation password.";
        }
       
        $sql = array(
            'password' => md5($pass),
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "Password updated successfully";
        }
    }
   
    function update_avatar($uid, $ola, $hda, $reg_val)
    {
        global $db;
       
        $handle = new upload($_FILES['hd_avatar']);
       
        $username = $db->_get_('USERNAME', USERS, array('UID' => $_SESSION['user']));
        $filed = "images/avatars/$username.JPG";
       
        $unlink = true;
       
        if(file_exists($filed))
        {
            if(unlink($filed))
            {
                $unlink = true;
            }
        }
       
        if($handle->uploaded && $unlink == true)
        {
            $handle->file_new_name_body = $username;
            $handle->file_new_name_ext = 'jpg';
            $handle->image_resize = true;
            $handle->image_x = 120;
            $handle->image_ratio_y = true;
            $handle->Process('images/avatars');
           
 
           
            if(!$handle->processed) {
                return $handle->error;
            }
           
            $handle-> Clean();
           
        } else {
            return $handle->error;
        }
       
        $sql = array(
            'avatar' => "$username.JPG",
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return 'Your avatar was successfully updated.';
        }
    }
   
    function update_website($uid, $web)
    {
        global $db, $regex;
       
        $sql = array(
            'website' => $web,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "Website updated successfully";
        }
    }
   
    function update_custom_title($uid, $ctitle)
    {
        global $db;
       
        $sql = array(
            'custom_title' => $ctitle,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "Custom title updated successfully";
        }
    }
   
    function update_msn($uid, $msn)
    {
        global $db;
       
        $sql = array(
            'MSN' => $msn,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "MSN updated successfully";
        }
    }
   
    function allow_email($uid, $allow_email)
    {
        global $db;
       
        $allow = (($allow_email == 1) ? 1 : 2);
       
        $sql = array(
            'allow_email' => $allow,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "You're email is now " . (($allow == 1) ? "allowed" : "not allowed");
        }
    }
   
    function show_email($uid, $show_email)
    {
        global $db;
       
        $show = (($show_email == 1) ? 1 : 2);
       
        $sql = array(
            'show_email' => $show,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "You're email is now " . (($show == 1) ? "public" : "not public");
        }
    }
   
    function contact_choice($uid, $contact_choice)
    {
        global $db;
       
        $choice = (($contact_choice == 1) ? 1 :
                  (($contact_choice == 2) ? 2 :
                  (($contact_choice == 3) ? 3 : 1)));
       
        $contact = (($contact_choice == 1) ? 'PM' :
                   (($contact_choice == 2) ? 'Email' :
                   (($contact_choice == 3) ? 'PM and/or Email' : 'PM')));
       
        $sql = array(
            'contact_type' => $choice,
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "You are going to be contacted by " . $contact . " from now on.";
        }
    }
   
    function update_signature($uid, $signature)
    {
        global $db;
       
        $sql = array(
            'signature' => mysql_real_escape_string($signature),
        );
       
        $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
       
        if($db->set_result_resource($sql, true))
        {
            return "You're signature was updated.";
        }
    }
}
  1. <?php
  2. class ucp {
  3.    
  4.     private $errors = 0;
  5.    
  6.     /*
  7.      * function __construct( void )
  8.      *
  9.      * The construct function for the UCP class
  10.      */
  11.    
  12.     function __construct()
  13.     {
  14.         if(!isset($_SESSION['user']))
  15.         {
  16.             header("LOCATION: index.php");
  17.         }
  18.     }
  19.    
  20.     /*
  21.      * function submit_account( string $email, string $conemail, string $pass, string $conpass, string $ola, string $hda, string $web, string $ctitle, string $msn, string $signature, string $allow_email, string $show_email, string $contact_choice)
  22.      *      @string $email - User's email
  23.      *      @string $conemail -  Same user's email
  24.      *      @string $pass - Users password
  25.      *      @string $conpass -  User's password retyped for confirmation
  26.      *      @string $ola - User's avatar local to the website
  27.      *      @string $hda - User's avatar from user's computer
  28.      *      @string $web - User's website
  29.      *      @string $ctitle - User's custom title
  30.      *      @string $msn - User's MSN
  31.      *      @string $signature - User's signature
  32.      *      @string $allow_email - User's choice wether or not they want to get email from other users
  33.      *      @string $show_email - User's choice wether they want their email to be securely shown
  34.      *      @string $contact_choice - User's contact choice. Possible values:
  35.      *                  1: PM
  36.      *                  2: Email
  37.      *                  3: Either
  38.      *      
  39.      * Basically a construct function for the account form
  40.      */
  41.    
  42.     function submit_account($email, $conemail, $pass, $conpass, $ola, $hd_avatar, $web, $ctitle, $msn, $signature, $allow_email, $show_email, $contact_choice)
  43.     {
  44.         global $db;
  45.        
  46.         // Initiating the return array
  47.         $return = array();
  48.        
  49.         $reg_var = $db->_get_('email', USERS, array('UID' => $_SESSION['user']));
  50.        
  51.         if($email != $reg_var)
  52.         {
  53.             $return[] = $this->update_email($_SESSION['user'], $email, $conemail);
  54.         }
  55.        
  56.         if(!empty($pass))
  57.         {
  58.             $return[] = $this->update_password($_SESSION['user'], $pass, $conpass);
  59.         }
  60.        
  61.         $reg_var = $db->_get_('avatar', USERS, array('UID' => $_SESSION['user']));
  62.         var_dump($_FILES['hd_avatar']);
  63.         if(sizeof($_FILES['hd_avatar'][0]) > 0)
  64.         {
  65.             $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
  66.         }
  67.        
  68.         $reg_var = $db->_get_('website', USERS, array('UID' => $_SESSION['user']));
  69.        
  70.         if($web != $reg_var)
  71.         {
  72.             $return[] = $this->update_website($_SESSION['user'], $web);
  73.         }
  74.        
  75.         $reg_var = $db->_get_('custom_title', USERS, array('UID' => $_SESSION['user']));
  76.        
  77.         if($ctitle != $reg_var)
  78.         {
  79.             $return[] = $this->update_custom_title($_SESSION['user'], $ctitle);
  80.         }
  81.        
  82.         $reg_var = $db->_get_('MSN', USERS, array('UID' => $_SESSION['user']));
  83.        
  84.         if($msn != $reg_var)
  85.         {
  86.             $return[] = $this->update_msn($_SESSION['user'], $msn);
  87.         }
  88.        
  89.         $reg_var = $db->_get_('signature', USERS, array('UID' => $_SESSION['user']));
  90.        
  91.         if($signature != $reg_var)
  92.         {
  93.             $return[] = $this->update_signature($_SESSION['user'], $signature);
  94.         }
  95.        
  96.         if($allow_email != 0)
  97.         {
  98.             $return[] = $this->allow_email($_SESSION['user'], $allow_email);
  99.         }
  100.        
  101.         if($show_email != 0)
  102.         {
  103.             $return[] = $this->show_email($_SESSION['user'], $show_email);
  104.         }
  105.        
  106.         if($contact_choice != 0)
  107.         {
  108.             $return[] = $this->contact_choice($_SESSION['user'], $contact_choice);
  109.         }
  110.        
  111.         // Returning the results
  112.         if(sizeof($return) > 0)
  113.         {
  114.             if($this->errors > 0)
  115.             {
  116.                 $type1 = ($errors > 1) ? "were" : 'was';
  117.                 $type2 = ($errors > 1) ? "'s" : null;
  118.                 $text = "<p>There $type1 $errors mistake$type2 in the form.</p>\n";
  119.             }
  120.             else
  121.             {
  122.                 $text = "<p>Your form was successfully submitted and your profile was edited.</p>\n";
  123.             }
  124.             $text .= "                <ul>\n";
  125.             foreach($return as $return_val)
  126.             {
  127.                 $text .= "                    <li>$return_val</li>\n";
  128.             }
  129.             $text .= "                </ul>\n";
  130.            
  131.             return trim($text);
  132.         }
  133.         else
  134.         {
  135.             return "<p>No changes were made.</p>\n";
  136.         }
  137.     }
  138.    
  139.     function update_email($uid, $email, $conemail)
  140.     {
  141.         global $db, $regex;
  142.        
  143.         if($email != $conemail)
  144.         {
  145.             $this->errors +1;
  146.             return "Your email does not match your confirmation email.";
  147.             break;
  148.         }
  149.        
  150.         if(!preg_match($regex['EMAIL'], $email) || !preg_match($regex['EMAIL'], $conemail))
  151.         {
  152.             $this->errors +1;
  153.             return "Your email are of incorrect type.";
  154.             break;
  155.         }
  156.        
  157.         $sql = array(
  158.             'email' => $email,
  159.         );
  160.        
  161.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  162.        
  163.         if($db->set_result_resource($sql, true))
  164.         {
  165.             return "Email updated successfully";
  166.         }
  167.     }
  168.    
  169.     function update_password($uid, $pass, $conpass)
  170.     {
  171.         global $db;
  172.        
  173.         if($pass != $conpass)
  174.         {
  175.             $this->errors +1;
  176.             return "Your password does not match your confirmation password.";
  177.         }
  178.        
  179.         $sql = array(
  180.             'password' => md5($pass),
  181.         );
  182.        
  183.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  184.        
  185.         if($db->set_result_resource($sql, true))
  186.         {
  187.             return "Password updated successfully";
  188.         }
  189.     }
  190.    
  191.     function update_avatar($uid, $ola, $hda, $reg_val)
  192.     {
  193.         global $db;
  194.        
  195.         $handle = new upload($_FILES['hd_avatar']);
  196.        
  197.         $username = $db->_get_('USERNAME', USERS, array('UID' => $_SESSION['user']));
  198.         $filed = "images/avatars/$username.JPG";
  199.        
  200.         $unlink = true;
  201.        
  202.         if(file_exists($filed))
  203.         {
  204.             if(unlink($filed))
  205.             {
  206.                 $unlink = true;
  207.             }
  208.         }
  209.        
  210.         if($handle->uploaded && $unlink == true)
  211.         {
  212.             $handle->file_new_name_body = $username;
  213.             $handle->file_new_name_ext = 'jpg';
  214.             $handle->image_resize = true;
  215.             $handle->image_x = 120;
  216.             $handle->image_ratio_y = true;
  217.             $handle->Process('images/avatars');
  218.            
  219.  
  220.            
  221.             if(!$handle->processed) {
  222.                 return $handle->error;
  223.             }
  224.            
  225.             $handle-> Clean();
  226.            
  227.         } else {
  228.             return $handle->error;
  229.         }
  230.        
  231.         $sql = array(
  232.             'avatar' => "$username.JPG",
  233.         );
  234.        
  235.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  236.        
  237.         if($db->set_result_resource($sql, true))
  238.         {
  239.             return 'Your avatar was successfully updated.';
  240.         }
  241.     }
  242.    
  243.     function update_website($uid, $web)
  244.     {
  245.         global $db, $regex;
  246.        
  247.         $sql = array(
  248.             'website' => $web,
  249.         );
  250.        
  251.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  252.        
  253.         if($db->set_result_resource($sql, true))
  254.         {
  255.             return "Website updated successfully";
  256.         }
  257.     }
  258.    
  259.     function update_custom_title($uid, $ctitle)
  260.     {
  261.         global $db;
  262.        
  263.         $sql = array(
  264.             'custom_title' => $ctitle,
  265.         );
  266.        
  267.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  268.        
  269.         if($db->set_result_resource($sql, true))
  270.         {
  271.             return "Custom title updated successfully";
  272.         }
  273.     }
  274.    
  275.     function update_msn($uid, $msn)
  276.     {
  277.         global $db;
  278.        
  279.         $sql = array(
  280.             'MSN' => $msn,
  281.         );
  282.        
  283.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  284.        
  285.         if($db->set_result_resource($sql, true))
  286.         {
  287.             return "MSN updated successfully";
  288.         }
  289.     }
  290.    
  291.     function allow_email($uid, $allow_email)
  292.     {
  293.         global $db;
  294.        
  295.         $allow = (($allow_email == 1) ? 1 : 2);
  296.        
  297.         $sql = array(
  298.             'allow_email' => $allow,
  299.         );
  300.        
  301.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  302.        
  303.         if($db->set_result_resource($sql, true))
  304.         {
  305.             return "You're email is now " . (($allow == 1) ? "allowed" : "not allowed");
  306.         }
  307.     }
  308.    
  309.     function show_email($uid, $show_email)
  310.     {
  311.         global $db;
  312.        
  313.         $show = (($show_email == 1) ? 1 : 2);
  314.        
  315.         $sql = array(
  316.             'show_email' => $show,
  317.         );
  318.        
  319.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  320.        
  321.         if($db->set_result_resource($sql, true))
  322.         {
  323.             return "You're email is now " . (($show == 1) ? "public" : "not public");
  324.         }
  325.     }
  326.    
  327.     function contact_choice($uid, $contact_choice)
  328.     {
  329.         global $db;
  330.        
  331.         $choice = (($contact_choice == 1) ? 1 :
  332.                   (($contact_choice == 2) ? 2 :
  333.                   (($contact_choice == 3) ? 3 : 1)));
  334.        
  335.         $contact = (($contact_choice == 1) ? 'PM' :
  336.                    (($contact_choice == 2) ? 'Email' :
  337.                    (($contact_choice == 3) ? 'PM and/or Email' : 'PM')));
  338.        
  339.         $sql = array(
  340.             'contact_type' => $choice,
  341.         );
  342.        
  343.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  344.        
  345.         if($db->set_result_resource($sql, true))
  346.         {
  347.             return "You are going to be contacted by " . $contact . " from now on.";
  348.         }
  349.     }
  350.    
  351.     function update_signature($uid, $signature)
  352.     {
  353.         global $db;
  354.        
  355.         $sql = array(
  356.             'signature' => mysql_real_escape_string($signature),
  357.         );
  358.        
  359.         $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
  360.        
  361.         if($db->set_result_resource($sql, true))
  362.         {
  363.             return "You're signature was updated.";
  364.         }
  365.     }
  366. }

I want to make the avatar file thing optional... I can either make the script ignore the avatar if it's filled in or not, or make it required every time the whole form is filled in. I got the others optional (Upon change from default), but the avatar sh*t is driving me nuts!

I tried to do the following to see if the avatar is filled in, but I guess the input type 'file' doesn't send anything VIA $_POST, which is dumb, but $_FILES['hd_avatar'][0] (even though it gives 0 when the field is not filled in and 7 [or whatever] when the filled is filled in) doesn't work... that makes the script ignore the avatar entirely :x

Code: [ Select ]
if(count($_FILES['hd_avatar']['name']) > 0)
{
    $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
  1. if(count($_FILES['hd_avatar']['name']) > 0)
  2. {
  3.     $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
  4. }


Help on this would be greatly appreciated. Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Nevermind, the following finally did the trick. About freaking time I tried that :lol:
Code: [ Select ]
if(!empty($_FILES['hd_avatar']['name']))
{
    $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
  1. if(!empty($_FILES['hd_avatar']['name']))
  2. {
  3.     $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
  4. }

Although I don't see how the other way didn't work...

Now I need to find a way to upload images from other sites (http://www.wedevoy.com/images/image.jpg), rather than always from hard drive. (As advanced as the class I got is, it doesn't do that :shock:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

The following doesn't do the trick.
Code: [ Select ]
$target_path = "images/avatars/";

$target_path = $target_path . basename($ola);

if(move_uploaded_file($ola, $target_path))
{
    return "The file ". basename($ola). " has been uploaded";
}
else
{
    return "There was an error uploading the file, please try again!";
}
  1. $target_path = "images/avatars/";
  2. $target_path = $target_path . basename($ola);
  3. if(move_uploaded_file($ola, $target_path))
  4. {
  5.     return "The file ". basename($ola). " has been uploaded";
  6. }
  7. else
  8. {
  9.     return "There was an error uploading the file, please try again!";
  10. }
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Doesn't do the trick for what ?

I'm not sure if you've hit a snag with the files uploaded via <input type="file/> or if you've moved on to uploading from the remote server. :scratchhead:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Oh, I've got the uploading VIA <input type="file"/> working, I need to upload from a remote server (http://www.domain.com/images/image.jpg).
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

This probably isnt the best way to go about this, but my first thought was to just run a wget command via exec. You can use the -P option to specify where you want to download the file.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

SpooF wrote:
This probably isnt the best way to go about this, but my first thought was to just run a wget command via exec

Sorry for my ignorance, but what command am I going to use? I have never really used CMD or linux stuff and don't know where to find the commands. Thanks.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

'wget' is a command line program that retreives files from a web servers.

Usage:
Code: [ Select ]
wget http://domain.com/somefile.etc


You would probably do something like.
Code: [ Select ]
exec('wget -P /your/absolute/path/goes/here/ '.$url);


not 100% sure if that will work.

You might also be able to use http://us3.php.net/curl
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

SpooF wrote:
'wget' is a command line program that retreives files from a web servers.

Usage:
Code: [ Select ]
wget http://domain.com/somefile.etc


You would probably do something like.
Code: [ Select ]
exec('wget -P /your/absolute/path/goes/here/ '.$url);


not 100% sure if that will work.

How would I be able to rename that file and move it to a certain directory, and replace the file with the same name if it exists?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Well you can download it to any folder you like, and you can easily rename it via rename - http://us2.php.net/rename
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

SpooF wrote:
Well you can download it to any folder you like, and you can easily rename it via rename - http://us2.php.net/rename

Thanks, I will try that :D

Just one more thing, how can I convert a file to jpg? Any image file? I don't know what it would be as I don't know what the user would submit, but I'd like to know how to convert images to jpg?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

http://us3.php.net/manual/en/book.image.php

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 67 guests
  • 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 post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.