SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file upload problem

    Hi

    Can anyone tell me why this file upload script does not work. I've struggled for several days now and I can't see what the issue is...



    <form enctype='multipart/form-data' action='addfile.php' method='post'>

    <?

    if ($_SERVER["REQUEST_METHOD"] == 'POST')
    {

    if ($_POST['step'] == 1)
    {

    ?>

    This is step 2<br />
    <input type='hidden' name='step' value='2'>
    <input type='hidden' name='files' value='<? $files = urlencode(serialize($_FILES)); echo $files; ?>'>
    <input type='submit' value='Upload'>

    <?

    }



    if ($_POST['step'] == 2)
    {

    $files = unserialize(urldecode($_POST['files']));

    $object_name = $files['object']['name'];

    $ext = substr(strrchr($object_name, "."), 0);
    $object_path = "../../objects/5".$ext;

    move_uploaded_file($files['object']['tmp_name'], $object_path);
    chmod($object_path, 0755);

    }

    }
    else
    {

    ?>

    This is step 1<br />
    <input type='hidden' name='step' value='1'>
    <input name='object' type='file'><br />
    <input type='submit' value='Upload'>

    <?

    }

    ?>

    </form>

  2. #2
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my simple upload, from a while back
    obviously chmod the $uploads directory to 777 before executing
    PHP Code:
    <form name="uploader" method="post" action="<? echo $PHP_SELF?>" enctype="multipart/form-data">
    <input type="file" name="image" style="width:300px;cursor:pointer">
    <input type="submit" name="upload" value="Upload Image">
    </form>
    <?php
    if($_POST['upload']) {

    if (
    $_FILES['image']['name'] == "") {
        echo 
    "Please select a file to upload!\n";
        exit;
    }
        
    $uploads "/home/user/public_html/uploads";

    move_uploaded_file($_FILES['image']['tmp_name'], "".$uploads."/".$_FILES['image']['name']) or die ("Couldn't upload file!");
          echo 
    "File uploaded";
    exit

  3. #3
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    For my personal curiosity, what do these attributes represent:
    style="width:300px ; cursor : pointer"

    Are you actually resizing the pictures here? If so what size would a thumbnail be? What do the cursor: pointer attributes represent?

    Thanks!

  4. #4
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tdob
    Hey,

    For my personal curiosity, what do these attributes represent:
    style="width:300px ; cursor : pointer"

    Are you actually resizing the pictures here? If so what size would a thumbnail be? What do the cursorointer attributes represent?

    Thanks!
    oh, I picked the "meat" off of one of my older codes, I would have to check what I was trying to do there

  5. #5
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >For my personal curiosity, what do these attributes represent:
    >style="width:300px ; cursor : pointer"

    its some css setting the file inputs width (useless as some browsers/systems don't display a field for the file input so it has no width) and the cursor to arrow when you hover over it. this has no bearing on the php in any way.

    a+
    gar


Bookmarks

Posting Permissions

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