Jump to content

Upload Image does not work :(


Kleidi

Recommended Posts

Hello everyone!

 

I'm working on a form that can upload an image on server and add the image name on mysql db. The add page works correctly, the image is uploaded correctly and the image name is inserted on the db. But, the edit page dows not work :( ... When i click on Send option on the edit page and i'm not adding any image, the image db field remains black, and, when i want to upload an image (change the image) via the edit page form, the image is not uploaded and the image db field remains blabk :(

Can you help me please?

 

add page

<?
include('header.php');
include ('includes/uploader.class.php');
    $uploader = new uploader();
    // Setting properties then Uploading the image
    $uploader->destDir = "D:/Program Files/VertrigoServ/www/oldi/imazhet/artikuj/";
$uploader->upload($_FILES['LajmeImg']);

echo '<div class="majtas">';
// Remember any variables incase the form validation finds errors.
$LajmeEmri = $_POST['LajmeEmri'];
$KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve
$LajmeIntro = $_POST['LajmeIntro'];
$LajmeTxt = $_POST['LajmeTxt'];
$LajmeAktiv = $_POST['LajmeAktiv'];
$LajmeTag = $_POST['LajmeTag'];
$LajmeVideo = $_POST['LajmeVideo'];
//$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise
$LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64
$LajmeLink = preg_replace("#[^a-z0-9\-_]#i", "",str_replace(' ', '_', $LajmeEmri)); // Ben Url automatikisht nga titulli (LajmeEmri) i lajmit

if(isset($_POST['add_lajme'])) {

$LajmeEmri = $_POST['LajmeEmri'];
$KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve
$LajmeIntro = $_POST['LajmeIntro'];
$LajmeTxt = $_POST['LajmeTxt'];
$LajmeAktiv = $_POST['LajmeAktiv'];
$LajmeTag = $_POST['LajmeTag'];
$LajmeVideo = $_POST['LajmeVideo'];
//$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise
$LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64
$LajmeLink = preg_replace("#[^a-z0-9\-_]#i", "",str_replace(' ', '_', $LajmeEmri)); // Ben Url automatikisht nga titulli (LajmeEmri) i lajmit

if(trim($KatLajmeID) == '0') {
    	$error = '<div class="error_message">Attention! Nuk ke zgjedhur kategorine.</div>';
    } else if(trim($LajmeIntro) == '') {
    	$error = '<div class="error_message">Attention! Nuk ke vene Intro.</div>';
} else if(trim($LajmeEmri) == '') {
    	$error = '<div class="error_message">Attention! Nuk ke vene emrin.</div>';
    } 

$count = mysql_num_rows(mysql_query("SELECT * FROM lajme WHERE LajmeLink='".$LajmeLink."'"));

if($count > 0) {
    	$error = '<div class="error_message">Ky emer/url gjendet ne database.</div>';
}

if($error == '') {

$sql = "INSERT INTO lajme (KatLajmeID, LajmeEmri, LajmeLink, LajmeIntro, LajmeTxt, LajmeAktiv, LajmeTag, LajmeVideo, LajmeImg)
			VALUES ('$KatLajmeID', '$LajmeEmri', '$LajmeLink', '$LajmeIntro', '$LajmeTxt', '$LajmeAktiv', '$LajmeTag', '$LajmeVideo', '$LajmeImg')";

$query = mysql_query($sql) or die("Fatal error: ".mysql_error());


echo "<h2>Success!</h2>";	
echo "<div class='success_message'>U Shtua me sukses lajmi <b>$LajmeEmri</b> ne kategorine <b>$KatLajmeID</b> .</div>";

echo "<h2>Te Dhenat e Lajmit</h2>";

echo "<ul class='success-reg'>";
echo "<li><span class='success-info'><b>Titulli</b></span>$LajmeEmri</li>";
echo "<li><span class='success-info'><b>Url</b></span>$LajmeLink</li>";
echo "<li><span class='success-info'><b>Kategoria</b></span>$KatLajmeID</li>";
echo "<li><span class='success-info'><b>Aktive</b></span>$LajmeAktiv</li>";
echo "</ul>";

echo "<h2>Cfare deshiron te besh tani?</h2><br />";
echo "Shko tek <a href='lajme_edit.php'>modifikimi i lajmeve</a>.</li>";

}

}

if(!isset($_POST['add_lajme']) || $error != '') {

echo $error;

?>

<h2>Shto Lajme</h2>

<form action="" method="post" enctype="multipart/form-data">
<label style="width: 28%;" for="KatLajmeID">Kategoria</label>
<select id="KatLajmeID" name="KatLajmeID" size="1">
<?php
$query="SELECT * FROM lajme_kategori ";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();
?>
<option selected value="0">Perzgjidh Kategorine</option>
<?
if ($num > 0 ) {
$i=0;
while ($i < $num) {
$LKatID = mysql_result($result,$i,"LKatID");
$LKatEmri = mysql_result($result,$i,"LKatEmri");
$LKatLink = mysql_result($result,$i,"LKatLink");
$LKatAktiv= mysql_result($result,$i,"LKatAktiv");
?>
<option value="<?php echo $LKatID ?>"><?php echo $LKatEmri ?></option>
<?php
++$i; } }
?>
</select>

<script type="text/javascript"> 
function toggle_LajmeLink(LajmeID) { 
    if (window.XMLHttpRequest) { 
        http = new XMLHttpRequest(); 
    } else if (window.ActiveXObject) { 
        http = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    handle = document.getElementById(LajmeID); 
    var url = '../ajax.php?'; 
    if(handle.value.length > 0) { 
        var fullurl = url + 'do=check_LajmeEmri_exists&LajmeEmri=' + encodeURIComponent(handle.value);
        http.open("GET", fullurl, true); 
        http.send(null); 
        http.onreadystatechange = statechange_LajmeEmri; 
    }else{ 
        document.getElementById('LajmeEmri').className = ''; 
    } 
} 

function statechange_LajmeEmri() { 
    if (http.readyState == 4) { 
        var xmlObj = http.responseXML; 
        var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data; 
        document.getElementById('LajmeEmri').className = html; 
    } 
} 
</script> 

<label>Titulli</label><input type="text" name="LajmeEmri" value="<?=$LajmeEmri;?>" onchange="toggle_LajmeEmri('LajmeEmri')" width="70%"  /><br />

<label>Intro</label><textarea id="LajmeIntro" name="LajmeIntro" value="<?=$LajmeIntro;?>"></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'LajmeIntro',
    {
        filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
</script><br />



<label>Lajmi</label><textarea id="LajmeTxt" name="LajmeTxt" value="<?=$LajmeTxt;?>"></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'LajmeTxt',
    {
        filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
</script><br /> 

<label>Fotografia</label> <input type="file" size="20" value="<?=$LajmeImg;?>" id="LajmeImg" name="LajmeImg" /><br />
<label>Video</label><textarea id="LajmeVideo" name="LajmeVideo"  value="<?=$LajmeVideo;?>" rows="4" wrap="soft" style="width:700px;" /></textarea><br />
<label>Tag</label><input id="LajmeTag" type="text" name="LajmeTag" value="<?=$LajmeTag;?>" /><br />
<label>Aktive</label><input id="LajmeAktiv" name="LajmeAktiv" type="checkbox" value="PO"><br />
<input type="submit" value="Vazhdo" name="add_lajme" />

</form>

<? } 
echo '</div>';
include('poshte.php');?>

 

edit page

<?php
include('header.php');
include ('includes/uploader.class.php');
    $uploader = new uploader();
    // Setting properties then Uploading the image
    $uploader->destDir = "D:/Program Files/VertrigoServ/www/oldi/imazhet/artikuj/";
    $uploader->upload($_FILES['LajmeImg']);

echo '<div class="majtas">';
if(!$_GET['lajmeid'] && !isset($_POST['do_edit']) && !isset($_POST['edit_lajme'])) {

echo $error;

// Shfaq listen e lajmeve
lajmet_lista();

}



// Has the edit form been submitted?

if(isset($_POST['do_edit'])) {

$LajmeID = $_POST['LajmeID'];
$LajmeEmri = $_POST['LajmeEmri'];
$KatLajmeID = $_POST['KatLajmeID']; // Kategoria Lajmeve
$LajmeIntro = $_POST['LajmeIntro'];
$LajmeTxt = $_POST['LajmeTxt'];
$LajmeAktiv = $_POST['LajmeAktiv'];
$LajmeTag = $_POST['LajmeTag'];
$LajmeVideo = $_POST['LajmeVideo'];
$LajmeLink = $_POST['LajmeLink'];
//$LajmeImg = $_FILES['LajmeImg']['name']; // Me autoName = False; regjistron ne db emrin real te fotografise
$LajmeImg = $uploader->source['name']; // Me autoName = true; regjistron ne db emrin random te fotografise i gjeneruar ne base64
$LajmeImg = $_POST['LajmeImg'];

$fshij = $_POST['fshij'];


// Ticked the 'delete category' box? If so, delete and echo message.	
if($fshij == 'fshij_LajmeID' && $error == '') {

$sql =  "DELETE FROM lajme WHERE  LajmeID=$LajmeID LIMIT 1";
$query = mysql_query($sql) or die("Fatal error: ".mysql_error());

echo "<h3>U Fshi</h3>";
echo "<div class='success_message'>Lajme <b>$LajmeID</b> u fshi nga sistemi.</div>";

echo "<h2>What to do now?</h2><br />";
echo "Go to the <a href='lajme_edit.php'>edit lajme</a> page.</li>";

} else {

// Validate the submitted information

	if(trim($LajmeID) == '0') {
        	$error = '<div class="error_message">LajmeID - Attention! You cannot edit the main Administrator, use database.</div>';
        } else if(trim($LajmeEmri) == '') {
        	$error = '<div class="error_message">LajmeEmri - Attention! You must enter a first name.</div>';
        } else if(trim($LajmeLink) == '') {
        	$error = '<div class="error_message">LajmeUrl - Attention! You must enter a last name.</div>';
        } 

// Password been entered? If so, validate and update information.

	if(trim($KatLajmeID) == '') {
    	$error = '<div class="error_message">Attention! Nuk ke zgjedhur kategorine.</div>';
    } else if(trim($LajmeIntro) == '') {
    	$error = '<div class="error_message">Attention! Nuk ke vene Intro.</div>';
} else if(trim($LajmeEmri) == '') {
    	$error = '<div class="error_message">Attention! Nuk ke vene emrin.</div>';
    } 

		if($error == '') {

		$sql = "UPDATE lajme SET KatLajmeID = '$KatLajmeID', LajmeEmri = '$LajmeEmri', LajmeLink = '$LajmeLink', LajmeIntro = '$LajmeIntro', LajmeTxt = '$LajmeTxt', LajmeVideo = '$LajmeVideo', LajmeTag = '$LajmeTag', LajmeImg = '$LajmeImg', LajmeAktiv = '$LajmeAktiv' WHERE LajmeID = '$LajmeID'";
		$query = mysql_query($sql) or die("Fatal error: ".mysql_error());

		// $sql2 = "SELECT * FROM lajme_kategori WHERE LKatAktiv = PO"; 
		//$sql2 = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag,  A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, B.LKatAktiv = LKatAktiv FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND LKatAktiv = PO AND LajmeAktiv = PO ";
		//$sql2 = "SELECT * FROM lajme_Kategori WHERE LKatID = '$KatLajmeID'";
		//$result2 = mysql_query($sql2);

		echo "<h2>U Modifikua</h2>";
		echo "<div class='success_message'>Lajmi u modifikua: <b>$LajmeEmri ($LajmeLink)</b> me ID <b>$LajmeID </b>.</div>";

		echo "<h2>What to do now?</h2><br />";
		echo "Go to the <a href='lajme_edit.php'>edit lajme</a> page.</li>";

		}


	}

}


// Has a category been selected to edit?

if($_GET['lajmeid'] && !isset($_POST['do_edit']) && !isset($_POST['edit_lajme']) || $error != '') {

$LajmeID = $_GET['lajmeid'];

$sql = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeImg AS LajmeImg, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, A.KatLajmeID AS KatLajmeID FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND A.LajmeID='$LajmeID'"; 
$result = mysql_query($sql);

$row = mysql_fetch_array($result);

$LajmeEmri = $row['LajmeEmri'];
$LajmeLink = $row['LajmeLink'];
$LajmeIntro = $row['LajmeIntro'];
$LajmeTxt = $row['LajmeTxt'];
$LajmeVideo = $row['LajmeVideo'];
$LajmeTag = $row['LajmeTag'];
$LajmeImg = $row['LajmeImg'];
$LajmeAktiv = $row['LajmeAktiv'];
$KatLajmeID = $row['KatLajmeID'];
$LKatEmri = $row['LKatEmri'];


echo $error;

echo "<h2>Informacionet per lajmin ( ".stripslashes($row['LajmeEmri'])." )</h2>";

?>

<form action="" method="post">
<input type="hidden" name="LajmeID" value="<?=$row['LajmeID'];?>" />

<label style="width: 28%;">Kategoria</label>
<select name="KatLajmeID">
<option selected value="<?=stripslashes($row['KatLajmeID']);?>"><?=$LKatEmri ?></option> <?php // Marrja e te dhenave ekzistente ?>
<?php
$sql2 = "SELECT * FROM lajme_kategori WHERE LKatAktiv = 'PO'"; // Query per te marre kategorite nga database
		$result2 = mysql_query($sql2);
?>
<?
while($kategoria = mysql_fetch_array($result2)) {
echo '<option value="'.stripslashes($kategoria['LKatID']).'">'.stripslashes($kategoria['LKatEmri']).'</option>'; // Lista e kategorive
}
?>
</select>

<label>Titulli</label>
<input type="text" name="LajmeEmri" value="<?=stripslashes($row['LajmeEmri']);?>" /><br />

<label>Linku</label>
<input type="text" name="LajmeLink" value="<?=stripslashes($row['LajmeLink']);?>" /><br />



<label>Intro</label><textarea id="LajmeIntro" name="LajmeIntro" /><?=stripslashes($row['LajmeIntro']);?></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'LajmeIntro',
    {
	filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
});
</script><br />



<label>Lajmi</label>
<textarea id="LajmeTxt" name="LajmeTxt" /><?=stripslashes($row['LajmeTxt']);?></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'LajmeTxt',
    {
	filebrowserBrowseUrl : 'includes/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : 'includes/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : 'includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });
</script><br /> 


<label>Video</label>
<textarea id="LajmeVideo" name="LajmeVideo" rows="6" wrap="soft" style="width:700px;" /><?=stripslashes($row['LajmeVideo']);?></textarea><br />


Fotografia: <img src="../imazhet/artikuj/<?=stripslashes($row['LajmeImg']);?>" width="150" align="middle" /><br />
<label>Fotografia</label> <input type="file" size="20" name="LajmeImg" value="<?=stripslashes($row['LajmeImg']);?>" /><br />

<label>Tag</label>
<input type="text" name="LajmeTag" value="<?=stripslashes($row['LajmeTag']);?>" /><br />

<label style="width: 50%;">Aktive</label>
<input id="LajmeAktiv" name="LajmeAktiv" type="checkbox" <?php if ($LajmeAktiv == "PO") { echo "checked";} ?> value="PO">
<br /><br />
<div class="error_message">Do fshish kete lajm? (Nuk kthehet mbrapsh!) <input type="checkbox" class="checkbox" name="fshij" value="fshij_LajmeID"></div>
<input type="submit" value="Ruaje" name="do_edit" />
</form>

<? } 
echo '</div>';
include('poshte.php'); ?>

uploaded class

<?php 
/**
* Uploader is a file transfer class. it can upload files and images.
* It also can resize and crop images.
* Works on PHP 5
* @author Alaa Al-Hussein
* @link http://www.freelancer-id.com/projects
* @version 1.0
* 
*/
class uploader{
/**
 * Array, The file object as $_FILES['element'].
 * String, file location.
 */
public $source;
/**
 * Destination file location as folder.
 */
public $destDir;
/**
 * Directory for Resized images.
 */
public $resizeDir;
/**
 * Directory for Cropped images.
 */
public $cropDir;
/**
 * stores information for uploading file
 */
private $info = '';
/**
 * Enabling autoName will generate an auto file name for the uploaded file.
 */
public $autoName = true;
/**
 * Handles the error when it occurs.
 */
private $errorMsg = '';
/**
 * new width for resizing and cropping.
 */
public $newWidth;
/**
 * new height for resizing and cropping.
 */
public $newHeight;
/**
 * TOP postion to cropping image.
 */
public $top = 0;
/**
 * LEFT position for cropping image.
 */
public $left = 0;
/**
 * JPG quality (0 - 100). used for image resizing or cropping.
 */
public $quality = 60;

public function __construct(){
	//nothing
}
/**
 * Uploads the file to the server.
 * @param Array $_FILES[]
 */
public function upload($source){
	if($source != ""){
		$this->source = $source;
	}
	if(is_array($this->source)){
		if($this->fileExists()){
			return false;
		}
		return $this->copyFile();
	} else {
		return $this->source;
	}
}
/**
 * return the error messages.
 * @return String messages.
 */
public function getError(){
	return $this->errorMsg;
}
/**
 * Get uploading information.
 */
public function getInfo(){
	return $this->info;
}
/**
 * Get file ex.
 */    
    function getEx(){
        return strtolower(substr($this->source['name'], strrpos($this->source['name'], '.') + 1));	
    } 
/**
 * Get random name.
 */     
    function randName(){
   return substr(base64_encode(uniqid()),0,10);
    }   
    
/**
 * Copy the uploaded file to destination.
 */
private function copyFile(){
	if(!$this->isWritable()){
		$this->errorMsg .= '<div>Error, the directory: ('.$this->destDir.') is not writable. Please fix the permission to be able to upload.</div>';
		return false;
	}
        
        $this->source['name'] = ($this->autoName) ? $this->randName().'.'.$this->getEx(): $this->source['name'];

	if(copy($this->source['tmp_name'],$this->destDir . $this->source['name'])){
		// Done.
		$this->info .= '<div>file was uploaded successfully.</div>';
	} else {
		$this->errorMsg .= '<div>Error, the file was not uploaded correctly because of an internal error. Please try again, if you see this message again, please contact web admin.</div>';
	}
}
/**
 * Checks if the file was uploaded.
 * @return boolean
 */
private function uploaded(){
	if($this->source['tmp_name']=="" || $this->source['error'] !=0){
		$this->errorMsg .= '<div>Error, file was not uploaded to the server. Please try again.</div>';
		return false;
	} else 
		return true;
}
/**
 * Prepares the directory.
 */
private function preDir(){
	if($this->destDir!="" && substr($this->destDir, -1,1) != "/"){
		$this->destDir = $this->destDir . '/';
	}
	if($this->resizeDir!="" && substr($this->resizeDir, -1,1) != "/"){
		$this->destDir = $this->resizeDir . '/';
	}
	if($this->cropDir!="" && substr($this->cropDir, -1,1) != "/"){
		$this->destDir = $this->cropDir . '/';
	}
}
/**
 * Check if the folder is writable or not.
 * @return boolean
 */
private function isWritable(){
	$err = false;
	if(!is_writeable($this->destDir) && $this->destDir!=""){
		$this->errorMsg .= '<div>Error, the directory ('.$this->destDir.') is not writeable. File could not be uploaded.</div>';
		$err = true;
	}
	if(!is_writeable($this->resizeDir) && $this->resizeDir!=""){
		$this->errorMsg .= '<div>Error, the directory ('.$this->resizeDir.') is not writeable. File could not be resized.</div>';
		$err = true;
	}
	if(!is_writeable($this->cropDir) && $this->cropDir!=""){
		$this->errorMsg .= '<div>Error, the directory ('.$this->cropDir.') is not writeable. File could not be cropped.</div>';
		$err = true;
	}
	if($err == true){
		return false;
	} else {
		return true;
	}
}
/**
 * Checks if the file exists on the server
 * @return boolean
 */
private function fileExists(){
	$this->preDir();
	if(file_exists($this->destDir.$this->source)){
		$this->errorMsg .= '<div>Upload error because file already exists.</div>';
		return true;
	} else {
		return false;
	}
}
/**
 /586742130./8532 Crops image.
 * @return String fileName or False on error
 */
public function crop($file='',$width='',$height='',$top='',$left=''){
	if($file!=""){ $this->source = $file;}
	if ($width != '') $this->newWidth = $width;
	if ($height != '') $this->newHeight = $height;
	if ($top != '') $this->top = $top;
	if ($left != '') $this->left = $left;
	return $this->_resize_crop(true);
}
/**
 * Resizes an image.
 * @return String fileName or False on error
 */
public function resize($file='',$width='',$height=''){
	if($file!=""){ $this->source = $file; }
	if($width != '') $this->newWidth = $width;
	if($height != '') $this->newHeight = $height;
	return $this->_resize_crop(false);
}
/**
 * Get the Temp file location for the file.
 * If the Source was a file location, it returns the same file location.
 * @return String Temp File Location
 */
private function getTemp(){
	if(is_array($this->source)){
		return $this->source['tmp_name'];
	} else {
		return $this->source;
	}
}
/**
 * Get the File location.
 * If the source was a file location, it returns the same file location.
 * @return String File Location
 */
private function getFile(){
	if(is_array($this->source)){
		return $this->source['name'];
	} else {
		return $this->source;
	}
}
/**
 * Resize or crop- the image.
 * @param boolean $crop
 * @return String fileName False on error
 */
private function _resize_crop ($crop) {
	$ext = explode(".",$this->getFile());
	$ext = strtolower(end($ext));
	list($width, $height) = getimagesize($this->getTemp());
	if(!$crop){
		$ratio = $width/$height;
		if ($this->newWidth/$this->newHeight > $ratio) {
			$this->newWidth = $this->newHeight*$ratio;
		} else {
			$this->newHeight = $this->newWidth/$ratio;
		}
	}
	$normal  = imagecreatetruecolor($this->newWidth, $this->newHeight);
	if($ext == "jpg") {
		$src = imagecreatefromjpeg($this->getTemp());
	} else if($ext == "gif") {
            $src = imagecreatefromgif ($this->getTemp());
	} else if($ext == "png") {
            $src = imagecreatefrompng ($this->getTemp());
	}
	if($crop){
		$pre = 'part_';
			if(imagecopy($normal, $src, 0, 0, $this->top, $this->left, $this->newWidth, $this->newHeight)){
				$this->info .= '<div>image was cropped and saved.</div>';
			}
			$dir = $this->cropDir;
	} else {
		$pre = 'thumb_';
		if(imagecopyresampled($normal, $src, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width, $height)){
			$this->info .= '<div>image was resized and saved.</div>';
		}
		$dir = $this->resizeDir;
	}
	if($ext == "jpg" || $ext == "jpeg") {
		imagejpeg($normal, $dir . $pre . $this->getFile(), $this->quality);
	} else if($ext == "gif") {
		imagegif ($normal, $dir . $pre . $this->getFile());
	} else if($ext == "png") {
		imagepng ($normal, $dir . $pre . $this->getFile(),0);
	}
	imagedestroy($src);
	return $src;
}
}
?>

 

Can someone help me, please?

 

Thank you in advance!

Link to comment
Share on other sites

I don't see enctype="multipart/form-data" for the edit page <form>.

Thanks for your reply ;)

 

It resolves only the upload issue. Now, the image is uploaded but it's name is not updated on the database. And, if i don't want to upload (modify) the existed image, what should i do? Bcz, if i leave blank the image label, the script update the database and the image field too :(

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.