Upload filename στα ελληνικα PlZ Help

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
inviribus
Δημοσιεύσεις: 10
Εγγραφή: 17 Ιουν 2009 12:16

Upload filename στα ελληνικα PlZ Help

Δημοσίευση από inviribus » 27 Απρ 2012 13:30

Καλημέρα σας

έχω ένα scriptaki που κανει upload μια photo σε ένα συγκεκριμένο directory πάνω στον server

Ενώ με αγγλικούς χαρακτήρες δουλεύει άψογα όταν ανέβει με ελληνικούς χαρακτήρες ανεβαίνουν κινέζικα και δεν τα δείχνει καθόλου μάλιστα στην βάση έχει κενό στην θέση του ονόματος η βάση είναι UTF8 σίγουρα στο directory ανεβαίνει αλλά το δείχνει κινέζικα

Μπορείτε να με βοηθήσετε

Ευχαριστώ πολύ

το script είναι το παρακάτω

Κώδικας: Επιλογή όλων


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File Upload</title>

<style type="text/css">
<!--
#main&#123;width&#58;500px; margin&#58;10px auto;&#125;
#box &#123;
	margin-bottom&#58;10px;
	width&#58; auto;
	padding&#58;4px;
	border&#58;solid 1px #DEDEDE;
	background&#58; #FFFFCC;
	display&#58;none;
&#125;
 
#start &#123;
	text-align&#58; center;
	margin&#58; .5em 0;
&#125;
body,td,th &#123;
	font-family&#58; Verdana, Arial, Helvetica, sans-serif;
	font-size&#58; 12px;
	color&#58; #666666;
&#125;
body &#123;
	background-color&#58; #ccdbff;
	background-image&#58; url&#40;&#41;;
	background-repeat&#58; repeat-x;
	margin-left&#58; 12px;
	margin-top&#58; 0px;
	margin-right&#58; 12px;
	margin-bottom&#58; 5px;
&#125;
a&#58;link &#123;
	color&#58; #0066FF;
	text-decoration&#58; none;
&#125;
a&#58;visited &#123;
	text-decoration&#58; none;
	color&#58; #0066FF;
&#125;
a&#58;hover &#123;
	text-decoration&#58; underline;
	color&#58; #0066FF;
&#125;
a&#58;active &#123;
	text-decoration&#58; none;
	color&#58; #0066FF;
&#125;

.warning&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/alert.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#FFFF66;
color&#58;#666666;
width&#58;590px;
height&#58;auto;
max-height&#58;70px;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
display&#58;none;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

.error&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/error.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#FF5959;
color&#58;#FFFFFF;
width&#58;590px;
height&#58;auto;
max-height&#58;70px;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

.success&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/ok.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#CAFF95;
color&#58;#666666;
width&#58;590px;
height&#58;auto;
max-height&#58;70px;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
display&#58;none;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

.upload_success&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/ok.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#CAFF95;
color&#58;#666666;
width&#58;590px;
height&#58;auto;
max-height&#58;70px;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

.confirm&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/error.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#FF5959;
color&#58;#FFFFFF;
width&#58;590px;
height&#58;auto;
max-height&#58;70px;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
display&#58;none;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

.upload_progress&#123;
cursor&#58;default;
background-image&#58;
url&#40;files/images/alert.png&#41;;
background-repeat&#58;no-repeat;
background-position&#58;12px 10px;
overflow&#58;hidden;
background-color&#58;#FFFF66;
color&#58;#666666;
width&#58;590px;
height&#58;auto;
min-height&#58;20px;
padding-left&#58;32px;
padding-right&#58;12px;
padding-top&#58;12px;
padding-bottom&#58;12px;
text-align&#58;left;
margin&#58;2px;
display&#58;none;
border-color&#58;#0066FF;border-style&#58;dashed;border-width&#58;1px;
&#125;

-->
</style>

<script type="text/javascript" src="files/javascripts/jquery.js"></script>
<script type="text/javascript" src="files/javascripts/jquery-easing.js"></script>
<script type="text/javascript" src="files/javascripts/jquery-geturlparam.js"></script>
<script type="text/javascript">
$&#40;document&#41;.ready&#40;function&#40;&#41;&#123;
  
jQuery.easing.def = "easeInOutExpo";

var get_id=$&#40;document&#41;.getUrlParam&#40;'id'&#41;;
var get_file=$&#40;document&#41;.getUrlParam&#40;'file'&#41;;
var get_action=$&#40;document&#41;.getUrlParam&#40;'action'&#41;;
var get_src=$&#40;document&#41;.getUrlParam&#40;'src'&#41;;

if &#40;get_file=='geturl' || get_action=='confirmdelete' || get_action=='delete'&#41;
&#123;
&#125;
else
&#123;  
$&#40;".error"&#41;.hide&#40;&#41;;
$&#40;".warning"&#41;.hide&#40;&#41;;
$&#40;".success"&#41;.hide&#40;&#41;;
$&#40;".confirm"&#41;.hide&#40;&#41;;
&#125;
  
$&#40;".warning"&#41;.click&#40;function&#40;event&#41;&#123;
$&#40;".warning"&#41;.fadeOut&#40;"slow"&#41;;
&#125;&#41;;

$&#40;".error"&#41;.click&#40;function&#40;event&#41;&#123;
$&#40;".error"&#41;.fadeOut&#40;"slow"&#41;;
&#125;&#41;;

$&#40;".success"&#41;.click&#40;function&#40;event&#41;&#123;
$&#40;".success"&#41;.fadeOut&#40;"slow"&#41;;
&#125;&#41;;  

$&#40;".upload_success"&#41;.click&#40;function&#40;event&#41;&#123;
$&#40;".upload_success"&#41;.fadeOut&#40;"slow"&#41;;
&#125;&#41;; 

if &#40;get_action=='delete'&#41;
&#123;
$&#40;".success"&#41;.html&#40;"File with ID "+get_id+" &#40;file&#58; "+get_src+"&#41; was successfully deleted!"&#41;;
$&#40;".success"&#41;.fadeIn&#40;"slow"&#41;;
&#125;

if &#40;get_action=='confirmdelete'&#41;
&#123;
$&#40;".confirm"&#41;.html&#40;"Are you sure you want to delete the file with ID&#58; "+get_id+" &#40;file&#58; "+get_src+"&#41;? <br/><br/><a href='home-image-uploadform.php?action=delete&amp;id="+get_id+"&amp;src="+get_src+"'>Yes</a> | <a href='#' class='close'>No</a>"&#41;;
$&#40;".confirm"&#41;.fadeIn&#40;"slow"&#41;;
&#125;

$&#40;".close"&#41;.click&#40;function&#40;event&#41;
&#123;
$&#40;".confirm"&#41;.fadeOut&#40;"slow"&#41;;
&#125;&#41;;

$&#40;".uploadbutton"&#41;.click&#40;function&#40;event&#41;&#123;
$&#40;".success"&#41;.hide&#40;&#41;;
$&#40;".error"&#41;.hide&#40;&#41;;
$&#40;".confirm"&#41;.hide&#40;&#41;;
$&#40;".upload_success"&#41;.hide&#40;&#41;;
$&#40;".uploadbutton"&#41;.hide&#40;&#41;;
$&#40;".upload_progress"&#41;.html&#40;"Uploading. Please wait..."&#41;;
$&#40;".upload_progress"&#41;.fadeIn&#40;"slow"&#41;;

&#125;&#41;;

&#125;&#41;;
  </script>

</head><body>
<br/><br/>
<?php

$overwrite=0;

$successful=1;

$upload_error_header="<div class='error' ><div><b> ";
$upload_error_footer="</b></div></div>";

$upload_success_header="<div class='upload_success' ><div><b> ";
$upload_success_footer="</b></div></div>";

ini_set&#40;"session.gc_maxlifetime","20800"&#41;;

$max_filesize = 500000;

$max_filesize_in_kbs = $max_filesize/1000;

$max_file_width = 222;
$max_file_height = 800;

$max_filename_length = 50;

$filename_to_md5 = 0;

$filename_to_lowercase = 1;

ini_set&#40;"session.gc_maxlifetime","36000"&#41;;

$file_extensions  = array&#40;'.jpg','.png','.gif',''&#41;;

$upload_dir = "../uploads/images/homepage/";

if &#40;$_GET&#91;'action'&#93;=='delete'&#41;
&#123;

$id=strip_tags&#40;$_GET&#91;'id'&#93;&#41;;
$src=strip_tags&#40;$_GET&#91;'src'&#93;&#41;;

$delete_query="DELETE FROM images WHERE row_id='$id' AND row_type='homepage' LIMIT 1";
mysql_query&#40;$delete_query&#41; or die&#40;'Error in Query&#58; ' . mysql_error&#40;&#41;&#41;;
unlink&#40;$upload_dir.$src&#41;;

&#125;


switch&#40;$_GET&#91;'file'&#93;&#41;
&#123;
case 'geturl'&#58;

function get_upload_timer&#40;&#41; &#123;
    $timer = explode&#40; ' ', microtime&#40;1&#41; &#41;;
    $timer = $timer&#91;1&#93; + $timer&#91;0&#93;;
    return $timer;
	&#125;

$start_upload_timer = get_upload_timer&#40;&#41;;

$overwrite=$_POST&#91;'overwrite'&#93;;

$file_name = $_FILES&#91;'userfile'&#93;&#91;'name'&#93;;
$temp_name = $_FILES&#91;'userfile'&#93;&#91;'tmp_name'&#93;;
$file_size = $_FILES&#91;'userfile'&#93;&#91;'size'&#93;;

$file_extension = strtolower&#40;substr&#40;$file_name,strrpos&#40;$file_name,"."&#41;&#41;&#41;;

$illegal_characters  = array&#40;$file_extension,"¦","*","«","»","¬","©","&","&#58;","&#402;","","¨","&#180;",";","//","/","\\","~","^","%","$","#","@","!","+","'","\"","=","?","<",">","|","`","&",",","."," "&#41;;

for&#40;$i=0, $size = sizeof&#40;$illegal_characters&#41;;$i < $size;$i++&#41;&#123;
  $file_name=str_replace&#40;$illegal_characters,"",$file_name&#41;;
 &#125;


$file_name=$file_name.$file_extension;


if &#40;$filename_to_md5 == 1&#41;&#123;$file_name=md5&#40;$file_name&#41;.$file_extension;&#125;


if &#40;$filename_to_lowercase == 1&#41;&#123;$file_name = strtolower&#40;$file_name&#41;;&#125;

$file_path = $upload_dir.$file_name;
list&#40;$file_width, $file_height, $type, $attr&#41; = getimagesize&#40;$temp_name&#41;;

$filesize_in_kbs=$file_size/1000;

if &#40;$file_name=="" && $successful==1&#41;&#123;$result_message= $upload_error_header."No file was selected!".$upload_error_footer;$successful=0;&#125;


if &#40;!in_array&#40;$file_extension, $file_extensions&#41; && $successful==1&#41;&#123;$result_message= $upload_error_header."This file type &#40;$file_extension&#41; is not allowed!".$upload_error_footer;$successful=0;&#125;

$file_to_check=$upload_dir.$file_name;
if &#40;file_exists&#40;$file_to_check&#41; && $successful==1 && !$overwrite==1&#41;&#123;$result_message= $upload_error_header."The file already exists!".$upload_error_footer;$successful=0;&#125;

if &#40;&#40;strlen &#40;basename&#40;&#40;$file_name&#41;&#41;&#41; > $max_filename_length&#41; && $successful==1&#41;&#123;$result_message= $upload_error_header."The file name is too long!".$upload_error_footer;$successful=0;&#125;

if&#40; $file_size > $max_filesize && $successful==1&#41;&#123;$result_message= $upload_error_header."The file size is too big in size!".$upload_error_footer;$successful=0;&#125;

if&#40; &#40;$file_width > $max_file_width || $file_height > $max_file_height&#41; && $successful==1&#41;&#123;$result_message= $upload_error_header."The file dimensions is larger than the ones allowed &#40;$max_file_width x $max_file_height&#41;".$upload_error_footer;$successful=0;&#125;

if &#40;$successful==1&#41;
&#123;
$result  =  move_uploaded_file&#40;$temp_name, $file_path&#41;;
if &#40;$result==1&#41;
&#123;
$insert_query="INSERT INTO images &#40;row_src,row_type&#41;
VALUES
&#40;'$file_name','homepage'&#41;";

mysql_query&#40;$insert_query&#41; or die&#40;'Error in Query&#58; ' . mysql_error&#40;&#41;&#41;;

$end_upload_timer = get_upload_timer&#40;&#41;;

$result_message= $upload_success_header."File was successfully uploaded! Upload completed in &#58; ".round&#40;$end_upload_timer - $start_upload_timer,4&#41;." seconds! ".$upload_success_footer;
&#125;
else
&#123;
$result_message= $upload_error_header."File could not be uploaded!".$upload_error_footer;
&#125;
&#125;

 
break;
default&#58;
&#125;

echo $result_message;
?>
<div class="confirm"></div>
<div class="success"></div>
<div class="upload_progress"></div>
  <form name="upload" style="width&#58;400px;overflow-x&#58;hidden;" id="upload" ENCTYPE="multipart/form-data" method="post" action="home-image-uploadform.php?file=geturl">
  <div id='alert' style="width&#58;400px;"></div><br/>
    <strong><img src="files/images/arrow_up.png" width="16" height="16" />Image Upload</strong><br />
    <br />
    <input type="file" id="userfile" name="userfile">
    <input type="submit" name="upload" value="Upload" class="uploadbutton"> 
    <img src="files/images/help.png" alt="Help" width="16" height="16" title="Select a file from your computer to upload" style="cursor&#58;help" /><br/>
    <br>
    <input type="checkbox" id="overwrite" name="overwrite" value="1"> Overwrite file if exists<br>
    <br/>
    The following file extensions are allowed&#58; <strong>
	<?php 
  $file_extensions=implode&#40;", ",$file_extensions&#41;;
  echo $file_extensions;
  ?>
  </strong><br/> 
    Maximum size&#58; <strong><?php echo $max_filesize_in_kbs." Kbs"; ?></strong>  | Max dimensions&#58; 
  <strong><?php echo $max_file_width." x ".$max_file_height; ?></strong> 
  </form>
<?php


$select_query = "SELECT * FROM images WHERE row_type='homepage' ORDER BY row_id DESC";


$select_result=mysql_query&#40;$select_query,$db_connection&#41;;
echo"<b><br/><div style='overflow-y&#58;scroll;overflow-x&#58;hidden;height&#58;450px;width&#58;650px;background-color&#58;#E6E6E6;'><table width='630' border='0' cellpadding='2' cellspacing='2'>";

while&#40;$row = mysql_fetch_array&#40;$select_result&#41;&#41;
  &#123;
  $imageid=$row&#91;'row_id'&#93;;
  $imagesrc=$row&#91;'row_src'&#93;;
  
    $file_check="../uploads/images/homepage/$imagesrc";
  list&#40;$width, $height, $type, $attr&#41; = getimagesize&#40;$file_check&#41;;
  $fsize=filesize&#40;$file_check&#41;;
  $fsize=$fsize/1000;

  echo "
<tr onmouseover=\"this.style.backgroundColor='#F0F3FF'\"; onmouseout=\"this.style.backgroundColor='transparent'\">
    <td width='630' align='left' valign='middle'><a href='../uploads/images/homepage/$imagesrc' onclick=\"javascript&#58;NewWindow&#40;this.href,'openwindow','".$height."','".$width."','yes','center','no','no','no','no'&#41;;return false\"><img src='../uploads/images/homepage/$imagesrc' border=0 alt='Preview' width='$width' height='$height' />";
	echo " $imagesrc</a><br/>filesize&#58; $fsize Kbs | dimensions&#58; $width x $height px</td>
    <td width='170' align='right' valign='bottom'><a href='#' style='cursor&#58;pointer' onclick='parent.document.newpost.home_imagesrc.value=\"$imagesrc\";'><img src='files/images/ok.png' border=0 alt='Use' />Use</a> | <img src='files/images/delete.png' border=0 alt='Delete' /><a href='home-image-uploadform.php?action=confirmdelete&amp;id=$imageid&amp;src=$imagesrc'>Delete</a></td>
  </tr>
  <tr>
    <td colspan='2' align='left' valign='middle' style='background-color&#58;#D7D7D7;font-size&#58;2px;'>&nbsp;</td>
  </tr>
  ";
  
  &#125;
  echo "</table></div><br/>";
?>

<script type="text/javascript" src="files/javascripts/open-window.js"></script>

</body>
</html>
<?php

mysql_close&#40;&#41;;

?>
[/code]

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες