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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Image not being passed through form

    Hello there,

    I have a little compact image upload page. The only problem with it is the image is not being passed through the form. I'm not sure why, I have used this same script before in multiple places, everything is the same, just doesn't work.


    Here is the script side.
    PHP Code:
    $current_image=$_FILES['image1']['name'];
                 
    $extension substr(strrchr($current_image'.'), 1);
                 if ((
    $extension!= "jpg") && ($extension != "jpeg") && ($extension != "png")) 
                 {
                     die(
    'Restricted Extension, did not upload.');
                 }
     
                 
    $limit_size 100000;
                 
    $file_size=$_FILES['image1']['size'];
                 if(
    $file_size >= $limit_size)
                 {
                     die(
    'Your file is too large, please pick a smaller file');
                 }
                 
    $time1 date("fYhis");
                 
    $new_image $time1 "." $extension;
                 
    $destination="images/".$new_image;
                 
    $action copy($_FILES['image1']['tmp_name'], $destination);
                 if (!
    $action
                 {
                     die(
    'An error occured, please try again later.');
                 } 
    Here is the form
    Code:
    echo '<form name="upload" method="post" action="index.php?page=p_upload&action=upload">';
    	echo 'Picture Name: <input type=text" name="name"><br />';
    	echo 'File: <input type="file" name="image1"><br />';
    	echo 'Privacy Settings: <select name="privacy"><option value="Everyone">Everyone</option><option value="Friends">Friends Only</option><option value="Me">Only Me</option></select><br />';
    	echo '<input type="submit" value="Upload"></form>';

    If anyone can point me in a direction to solving this, it will be much appreciated.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,234
    Thanks
    51
    Thanked 100 Times in 99 Posts
    Which error are you getting?

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by blackrain87 View Post
    PHP Code:
                 $action copy($_FILES['image1']['tmp_name'], $destination); 
    That should be move_uploaded_file().
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    The error is that the file extension is restricted. That is because there is no file being passed!

    When I echo out the variable $current_image, it is blank. It is as if it is never being passed through the form. I have never had this happen before.

  • #5
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,388
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    <form name="upload" method="post" action="index.php?page=p_upload&action=upload">

    Needs to have multi-part ...

    <form name="upload" method="post" action="index.php" enctype="multipart/form-data">

    and don't use those URL variables ... those need to be hidden in the form ...

    <form name="upload" method="post" action="index.php" enctype="multipart/form-data">
    <input type="hidden" name="page" value="p_upload">
    <input type="hidden" name="action" value="upload">

    and finally ... how are you reading those form variables in your script?
    I don't see any $_POST['xxx'] references for your form variable names.



    .
    Last edited by mlseim; 09-19-2011 at 09:32 PM.

  • #6
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Ah thank you! Such a little part that I forgot can make all the difference.

    And the $_POST variables were called earlier on the page.


    Thanks again!


  •  

    Posting Permissions

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