Help - Search - Members - Calendar
Full Version: Advanced Image uploader
Weborum Webmaster Forum > Web Page Design > PHP
edevil
I dont know why the file isnt being uploaded. Please try out this code and tell me what you get.

PHP
function form() {
// The upload form
echo '<h2>Upload Files</h2>

<br />Supported file types: <b>jpg, jpeg, bmp, gif and png</b>
<br /><br />Maximum filesize: <b>2 MB</b>

<form action="upload.php?do=upload" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<br />Files: <br /><input size="54" type="file" name="userphoto"><br />
<input type="submit" value="Upload">
</form>';

} //Ending the function 'form'


function upload() {

// The first file
$maxfilesize = 2000000;

//Checkin if the file was uploaded
if (!is_uploaded_file($_FILES['userphoto']['tmp_name'])) {   // If-1
form();
echo 'You must select a file to upload.';

} else {

//Checking if the file size exceeded the limit
           if ($_FILES['userphoto']['size'] > $maxfilesize) {   //If-2
           form();
           echo 'Your file is too big. The file size limit is 2 MB.';

           } else {
           $ext = strrchr($_FILES['userphoto']['name'], ".");
                //if-3
                if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".bmp" AND $ext !=".png" AND $ext != ".gif" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP" AND $ext !=".PNG")
                {
                form();
                echo 'The file format is unacceptable.';
                } else {

                       //If-4
                       if( (substr($file,-3)=="gif") || (substr($file,-3)=="jpg")  || (substr($file,-3)=="jpeg") || (substr($file,-3)=="bmp") || (substr($file,-3)=="png") || (substr($file,-3)=="GIF") || (substr($file,-3)=="JPG")  || (substr($file,-3)=="JPEG") || (substr($file,-3)=="BMP") || (substr($file,-3)=="PNG")  )
                       {
                       form();

                       $location = 'http://'.$_SERVER["SERVER_NAME"].'/'.md5($_SESSION['s_username']);
                       $newname = $_FILES['userphoto']['name'];
                       $newname = strtolower($newname);
                       str_replace(" ", "_", $newname);
                       $destfile1 =  $location.'/'.$newname;
                       move_uploaded_file($_FILES['userphoto']['tmp_name'],$destfile1);

                       // Showing the image that has been uploaded

                       echo"<table width='520' align='center'>
                       <p>
                       <tr>
                       <td width='220' valign='top' align='center'>

                       <img src='phpThumb.php?src=$destfile1&w=100'/>
                       <br />File size: ".file_size($destfile1)."
                       <br /><br />
                       <a href=\"javascript:popImage('$destfile1','$destfile1')\"> [full size]</a>
                       <br /><br />
                       <a href='delete.php?file=$destfile1'> [delete] </a>
                       <br /><br />
                       <a href=''> [send to a friend] </a>

                       </td>

                       <td width='300'>
                       URL: <input size='54' value='http://".$_SERVER["SERVER_NAME"]."/".$destfile1."' onClick='highlight(this);' />
                       <br /> <br />
                       HTML: <input size='54' value='". htmlspecialchars ("<img src=\"".'http://'.$_SERVER["SERVER_NAME"]."/".$destfile1."\" alt=\"This image is hosted by ImageVoid.com\" />")."' onClick='highlight(this);' />
                       <br /> <br />
                       IMG: <input size='54' value='". htmlspecialchars ("[IMG]".'http://'.$_SERVER["SERVER_NAME"]."/".$destfile1."[/IMG]")."' onClick='highlight(this);' />
                       </td>
                       </tr>
                       </table>";
                       // end-The Image


                       } else { echo 'The file format is acceptable, the file is also within the size limit but for some reason this ###### aint workin'; } //ending If-4 directly
                } //ending else of if-3
           } //ending else of if-2

} //ending else of if-1

}; //ending the function 'upload'


//The switch
switch($_GET['do']){

case 'form':
form();
break;

case 'upload':
upload();
break;

default:
form();

} //end-the switch



Please help me find the fault in the code.

Thanks in advance,
Azad
h198848
programmer design is ok
pehps there s some little errors

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.