tags:

views:

58

answers:

2
 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>

A: 

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.

Sarfraz
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
piemesons
If that code has always worked before, and is not working on a new folder or project, it is almost definitely a permissions problem.
jaywon
how can i change a folder's permission using php script..???
piemesons
you need to use ftp client software to change permissions by right clickingon folder and typing 755also make sure that your form has enctype set to multipart. Thanks
Sarfraz
A: 

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()

jaywon
how can i change permissions of a folder using php script..!!!
piemesons
to change permissions on a folder programmitcally take a look at the chmod() function in PHP
jaywon