开发者

Problem in php upload script?

 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>


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜