upload image problem

Discussion in 'PHP' started by Mina Samy, Feb 16, 2010.

  1. #1
    Hello every one
    i have the following code works in local host but it doesnt in the server
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <form enctype="multipart/form-data" action="upload_rename_ac.php" method="post"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000000000" /> 
    Choose a file to upload: <input name="uploaded_file" type="file" /><input type="submit" value="Upload" /> 
    </form> 
    
    The script (upload.php): 
    
    <?php 
    //Check that we have a file 
    if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { 
    //Check if the file is JPEG image and it's size is less than 350Kb 
    $filename = basename($_FILES['uploaded_file']['name']); 
    $ext = substr($filename, strrpos($filename, '.') + 1); 
    //Determine the path to which we want to save this file 
    $newname = dirname(__FILE__).'/file/'.$filename; 
    //Check if the file with the same name is already exists on the server 
    if (!file_exists($newname)) { 
    //Attempt to move the uploaded file to it's new place 
    if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { 
    echo "It's done! The file has been saved as: ".$newname; 
    } else { 
    echo "Error: A problem occurred during file upload!"; 
    } 
    } else { 
    echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists."; 
    } 
    } else { 
    echo "Error: No file uploaded"; 
    } 
    ?> 
    </body>
    </html>
    
    Code (markup):
    and i give the permission to server folder to be 777

    any suggestion?
     
    Mina Samy, Feb 16, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    are you receiving error / notice or warning??
    on your condition what message is being post?
     
    bartolay13, Feb 16, 2010 IP
  3. bitist

    bitist Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've tested your code on my local and remote server. On both places it worked well.
     
    bitist, Feb 17, 2010 IP
  4. Mina Samy

    Mina Samy Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    there is no error there is no warning
    but the images didn't upload in the folder!!! should i do something in the server to make it work??

    Thanks
     
    Mina Samy, Feb 17, 2010 IP
  5. bitist

    bitist Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You should set up .htaccess to not inhibit the errors.
    Other way is to echo some debug info like $newname;
     
    bitist, Feb 17, 2010 IP
  6. Mina Samy

    Mina Samy Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry i am beginner,
    How can i setup .htaccess??
     
    Mina Samy, Feb 17, 2010 IP
  7. bitist

    bitist Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Create a file in the root of your script: .htaccess
    Add these line into that:
    
    php_value display_errors 1
    php_value error_reporting 2039
    
    Code (markup):
     
    bitist, Feb 17, 2010 IP
  8. Mina Samy

    Mina Samy Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I did that but i didnt receive any errors or warnings !!!

    hint: my folder to save pics is not the folder which includes uploadImages.php
    in other words my there is folder1 which inclide folder"uploaded images" and folder"files" which contain .php files , is that the reason to didnt receive any errors!!
     
    Mina Samy, Feb 20, 2010 IP