SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Multiuser Profile Photo Upload

    Hi there,

    I am currently doing a website that will enable multiuser to have their accessing account. When come to the profile photo upload part, I have problem.

    This is the code I have now:

    HTML form:
    HTML Code:
    HTML Code:
    <form name="addPict" action="Photo.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="2048000">
    <input type="file" name="srcImg" size="60">
    <input type="submit" value="submit">
    </form>
    PHP page (Photo.php):
    PHP Code:
    PHP Code:
    <?php 
    foreach($_REQUEST as $K => $V){ 
    $
    $K $V


    $root_dir "accounts"

    if(isset(
    $_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>2097152){ 
    $action 'Photo.php?error… FAILED, file is too large!'
    header("Location: $action"); 
    die(); 


    if(
    $srcImg_type == "image/x-png" 
    || $srcImg_type == "image/png" 
    || $srcImg_type == "image/gif" 
    || $srcImg_type == "image/gif" 
    || $srcImg_type == "image/pjpeg" 
    || $srcImg_type == "image/jpeg"){ 
    }else{ 
    $action 'Photo.php?error… FAILED, is not a jpg, gif or png file!'
    header("Location: $action"); 
    die(); 


    $txtname strtolower(basename($srcImg)); 

    $result = @move_uploaded_file($srcImg_tmp$txtname); 

    if(!
    file_exists($root_dir)){ 
    mkdir($root_dir); 
    chmod($root_dir0777); 


    $getProfileFile $root_dir."/".$txtname

    copy($txtname,$getProfileFile); 

    @
    unlink($txtname); 
    ?>
    When I try to preview my script locally, it says "The page isn't redirecting properly". How to get the code run correctly? Please advice.

  2. #2
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There is so much wrong here...first the foreach at the top with "_REQUEST" you should not be doing that or be using _REQUEST in that way. Next is the way the you are determining the type of the file. That is quite bad. Lots of bad things going on here...
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    There is so much wrong here...first the foreach at the top with "_REQUEST" you should not be doing that or be using _REQUEST in that way. Next is the way the you are determining the type of the file. That is quite bad. Lots of bad things going on here...
    Please advice how should I corrected my code so it would work fine, I am quite new to php and this is my 1st project on it. Thanks in advance.


Tags for this Thread

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
  •