1
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

define ("MAX_SIZE","2000"); 

if( isset($_FILES['file_upload']))
 {

$errors=0;
$image=$_FILES['file_upload']['name'];
if ($image) 
{
    $filename = stripslashes($_FILES['file_upload']['name']);
    $extension = getExtension($filename);
    $extension = strtolower($extension);
    if (($extension != "jpg") && ($extension != "bmp") && ($extension != "png") && ($extension != "gif")) 
        {
            echo '<h1>Unknown extension!</h1>';
            $errors=1;
        }
    else
        {
            $size=filesize($_FILES['file_upload']['tmp_name']);
            if ($size > MAX_SIZE*1024)
            {
                echo '<h1>You have exceeded the size limit!</h1>';
                $errors=1;
            }
                $random_name=md5(uniqid(mt_rand(), true)).'.'.$extension;   
                $from=$_FILES['file_upload']['tmp_name'];               
                $newname='"temp_images/'.$random_name.'"';                      
                rename($from, $newname);     Problm is here?????
                                    //move_uploaded_file($from, $newname); Even tried this

            }   
}       

}

I dont know why images are not moving in temp_images folder..Can anybody help me.Thanks in advance.

Edit:

HTML FORM:

 <form name="form_upload" action="<?=$PHP_SELF?>"  method="post" enctype="multipart/form-data">
                                        <table   class='nryo_modal_div_table' align='center'>
<tr>
<td align='left'  class='response_color_ok'>
Select File:
    </td>                                               </tr>                                       <tr>

1
  • Can you post your html form too? Commented Dec 7, 2009 at 7:35

2 Answers 2

1

Make sure that temp_images folder has write permissions; chmod to 755.

Also make sure that you have specified enctype=multipart on the form used to upload the images.

Sign up to request clarification or add additional context in comments.

3 Comments

I never cared about the permissions of a folder, i m using windows and apache and we just create a folder and write the code acc to that. by default every time when i use code like this, it always worked..I dont know what happenin this time
If that code has always worked before, and is not working on a new folder or project, it is almost definitely a permissions problem.
you need to use ftp client software to change permissions by right clickingon folder and typing 755 also make sure that your form has enctype set to multipart. Thanks
0

You may want to try using the move_uploaded_file function instead of the rename function. As noted by sarfraz, also check that the temp_images folder has the proper permissions set.

Something like this is what I usually do:

if(move_uploaded_file($_FILES['file_upload']['tmp_name'], $newname)) {
  //move okay
}else{
  //move not okay
}

To change a folder's permissions programmatically take a look at the PHP function chmod()

1 Comment

to change permissions on a folder programmitcally take a look at the chmod() function in PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.