|
19-02-2009, 17:42
|
|
|
חבר מתאריך: 06.06.07
הודעות: 749
|
|
מה המצב
אני משתמש בסקריפט הבא
אבל יש לי בעיה
מה שקורה זה ככה
המערכת שואלת האם התמונה הועלת
אם כן
היא שולחת נתונים לפוקציה IMAGERESIZE כדי ליצור עוד תמונה בתקיה אחרת
הבעיה היא שהמערכת נותת לי ERROR שאין תמונה.
התמונה קיימת בתיקיה של SRC אני לא יודע להמערכת לא מזהה אותה.
הפונקציה עובדת לי על ידי הסקריפט הבא, אתם רק צריכים ליצור בכונן D את שתי התיקיות
newpic ובתוכה
new
קוד PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head>
<body> <?php if(isset($_POST['h']) && $_POST['h']=='h') { echo 'OK<br />'; $size = $_FILES['file']['size']; echo $size; echo '<br />'; echo $_FILES['file']['type']; echo '<br />'; echo $_FILES['file']['name']; echo '<br />'; echo $_FILES['file']['tmp_name']; echo '<br />'; $s = getimagesize($_FILES['file']['tmp_name']); $w = $s[0]; $h = $s[1]; //echo $s[2]; //echo $s[3]; echo $w / 155; function ImageResize($src,$width,$height,$output) {
$info = explode(".",$src); $ext = strtolower($info[1]);
if($ext == "jpeg" || $ext == "jpg") { $source_image = imagecreatefromjpeg($src); } elseif($ext == "gif") { $source_image = imagecreatefromgif($src); } else { die("Unknown image file type. (know only jpeg,jpg,gif) Filename supplied: $src"); }
$filesize = (list($awidth,$aheight) = getimagesize($src));
$output_image = imagecreatetruecolor ($width, $height);
imagecopyresampled ($output_image, $source_image, 0,0,0,0, $width, $height, $awidth, $aheight);
if($ext == "jpeg" || $ext == "jpg") { imagejpeg ($output_image,$output,100); } else if ($ext == "gif") { imagegif($output_image,$output,100); }
imagedestroy ($source_image); imagedestroy ($output_image); } if(move_uploaded_file($_FILES['file']['tmp_name'],'D:\\newpic\\'.$_FILES['file']['name'])) { ImageResize('D:\\newpic\\'.$_FILES['file']['name'],'135','160','D:\\newpic\\new\\'.$_FILES['file']['name']); } } ?> <form method="post" enctype="multipart/form-data"> <input type="hidden" id="h" name="h" value="h" /> <input type="file" id="file" name="file" /> <input type="submit" id="sub" name="sub" value="sub" /> </form> </body> </html>
הפונקציה להקטנת תמונה
קוד PHP:
function ImageResize($src,$width,$height,$output) { $info = explode(".",$src); $ext = strtolower($info[1]); if($ext == "jpeg" || $ext == "jpg" || $ext == "JPG" || $ext == "JPEG") { $source_image = imagecreatefromjpeg($src); } elseif($ext == "gif" || $ext == "GIF") { $source_image = imagecreatefromgif($src); } else { die("Unknown image file type. (know only jpeg,jpg,gif) Filename supplied: $src"); } echo $source_image; $filesize = (list($awidth,$aheight) = getimagesize($src));
$output_image = imagecreatetruecolor ($width, $height);
imagecopyresampled ($output_image, $source_image, 0,0,0,0, $width, $height, $awidth, $aheight);
if($ext == "jpeg" || $ext == "jpg" || $ext == "JPG" || $ext == "JPEG") { imagejpeg ($output_image,$output,100); } else if ($ext == "gif" || $ext == "GIF") { imagegif($output_image,$output,100); }
imagedestroy ($source_image); imagedestroy ($output_image); }
זאת הפונקציה שקוראת לפונקציה שמקטינה את גודל התמונה
קוד PHP:
if(move_uploaded_file($_FILES['myfile']['tmp_name'], '../' . $dir . $_FILES['myfile']['name'])) { //echo $_FILES['myfile']['name'].'<br>'; $picsrc = $dir.$_FILES['myfile']['name']; $picnewsrc = $dir.'smallpic/'.$_FILES['myfile']['name']; //echo $picnewsrc; ImageResize($picsrc,'135','165',$picnewsrc);
|
|