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 9 of 9
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts

    Problems with uploader

    I'm having problems with my "uploader". The problem is that it's not uploading. I get this error:

    Warning: Unable to open 'C:\\WINDOWS\\Desktop\\dude.JPG' for reading: No such file or directory in /home/chatterspics/public_html/register/index.php on line 158


    And my code is:

    PHP Code:
    if ($photo != "")
                    {
                       
    // copy the file from the temporary upload position to where you want it
                        
    copy($photo"../users/$username/$username.gif") or die("<b>Error:</b> could not copy file.");

                        
    // tell them it worked
                        
    echo "";
                    }
                    else
                    {
                        
    // tell them to browse for a file
                        
    copy("nophoto.gif""../users/$username/$username.gif");
                        echo 
    "You must select a file to upload. If there was an error, please email [email]technical@chatterspics.com[/email] with your photo, stating your username and password";
                    } 
    Anyone got any ideas on how to do it? I've looked at php.net but I got confused and more lost than I am now.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    PHP Code:
    <?
    if($HTTP_POST_FILES['infile']['tmp_name'])
    {
     if(!
    copy($HTTP_POST_FILES['infile']['tmp_name'],$new_home_for_image.$HTTP_POST_FILES['infile']['name']))
      {
       echo 
    "doh";
      }else{
       echo 
    "whoot!";
      }
    }
    ?>

    <form action="<?=$_SERVER[PHP_SELF];?>" name="bella" method="post" ENCTYPE="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="150000">
    <input type="file" name="infile"><br />
    <input type="submit" name="submit" value="submit" style="width:230" width="230">
    </form>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure that doing just that will work. Try reading over this one.
    PHP Code:
    <?
    $dir
    ="uploaded_files"// Directory name to upload files to
    if ($myfile){
      
    $ext substr ($myfile, -4); // Strip all but the file extension
    }
    $filetypes = array (".bmp",".jpg",".gif"); // File entensions to accept
      
    if (is_uploaded_file($myfile)){
        
    $filename=$HTTP_POST_FILES['myfile']['name'];
        
    copy ($myfile,"$dir/$filename") or die("Unable to upload file"); // Upload file
      
    }
      if (
    is_uploaded_file($myfile)){
        echo 
    "<p style=\"color:green;\">File uploaded sucessfully</p>"// On Success
      
    }else{
        echo 
    "<p style=\"color:red;\">Choose a file</p>"// Text to display before upload
      
    }
    ?>
    <form action="upload.php" enctype="multipart/form-data" method="post">
    <input type="file" name="myfile"><br><br>
    <input type="hidden" name="MAX_FILE_SIZE" value="10240000">
    <input type="submit" value="Upload">
    </form>
    Offtone.com - In the works...

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I'm wanting to rename the file once it's uploaded and moved to a directory. Which do I change on there to do that?

    I want it naming by their username ($username)

    Thanks for your help so far
    Last edited by Nightfire; 07-02-2002 at 02:36 AM.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    well I can assure you that the one I posted earlier works ..but is_uploaded_file() or move_uploaded_file() are supposed to be safer

    PHP Code:
    <?php 
    move_uploaded_file
    ($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file".$HTTP_POST_FILES['userfile']['name']);
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Back

    I'm now using your uploader, firepages. I saw in devshed you gave an answer on howto rename the file when it was uploaded:

    $int = rename($filename,$newfilename);

    Where will I put this in your code?

    Sorry for being dumb

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    As SYP}{ER points out you have to get the filetype as well


    PHP Code:
    <?
    $user
    ="joe";
    if(
    $HTTP_POST_FILES['infile']['tmp_name'])
    {
      
    $path=$new_home_for_image.$HTTP_POST_FILES['infile']['name'];
     if(!
    copy($HTTP_POST_FILES['infile']['tmp_name'],$path))
      {
       echo 
    "doh";
      }else{
      
    $type=array('','.gif','.jpg','.png','.swf');
      
    $bits=getimagesize($path);
      
    $newname=$user.$type[$bits[2]];
      if(
    rename($path,str_replace($HTTP_POST_FILES['infile']['name'],$newname,$path)))
        {
          echo 
    "whoot!";
        }
      }
    }
    ?>
    or just rename when copying

    PHP Code:
    <?
    $user
    ="joe";
    if(
    $HTTP_POST_FILES['infile']['tmp_name'])

      
    $path=$new_home_for_image.$HTTP_POST_FILES['infile']['name'];
      
    $type=array('','.gif','.jpg','.png','.swf');
      
    $bits=getimagesize($path);
      
    $newname=$user.$type[$bits[2]];
      
     if(!
    copy($HTTP_POST_FILES['infile']['tmp_name'],str_replace($HTTP_POST_FILES['infile']['name'],$newname,$path)))
      {
       echo 
    "doh";
      }else{
          echo 
    "whoot!";
      }
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Thanks That worked

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I'm getting an error when there's no image uploaded:

    Warning: Unable to open 'none' for reading: No such file or directory in /home/chatterspics/public_html/register/index.php on line 189

    PHP Code:
    $new_home_for_image="../users/$username/";
                if(
    $HTTP_POST_FILES['photo']['tmp_name'])
                {
                  
    $path=$new_home_for_image.$HTTP_POST_FILES['photo']['name'];
                  if(!
    copy($HTTP_POST_FILES['photo']['tmp_name'],$path))
                  {
                   
    copy("nophoto.gif","../users/$username/nophoto.gif");
                  }else{
                  
    $type=array('','.gif','.jpg');
                  
    $bits=getimagesize($path);
                  
    $newname=$username.$type[$bits[2]];
                   if(
    rename($path,str_replace($HTTP_POST_FILES['photo']['name'],$newname,$path)))
                    {
                      echo 
    "";
                    }
                  }
                } 
    Line 189 is

    PHP Code:
    if(!copy($HTTP_POST_FILES['photo']['tmp_name'],$path)) 
    I don't understand it, coz the nophoto.gif image is being copied if nothing has been uploaded, and it's also uploaded image the users are sending.
    Last edited by Nightfire; 07-02-2002 at 06:33 PM.


  •  

    Posting Permissions

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