Jump to content

Upload image


regoch

Recommended Posts

Hi!

Got a code for uploading images that is working fine for few years and get it working in 20. etc pages. But my friend now buy a hosting that don't even lets phpinfo();, they block it. When i call to see why I can't get my script for image upload to work they say that i must make tmp folder to temporary put there images before moving to my folder. Never need temp folder before, so I don't know what to edit/add in my code to get t work. Or to get him to change hosting company!  Image name get in mysql but image won't load in folder "slike".

<?php
require_once('zastita.php');
//Start session
session_start();

//Podaci za spajanje na bazu podataka
require_once('config.php');

//Array za provjeru jesu li ispunjena sva polja
$errmsg_arr = array();

//Isključivanje provjere jesu li ispunjena sva polja
$errflag = false;

//Spajanje na mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Greška prilikom spajanja na server: ' . mysql_error());
}

//Odabir baze podataka
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Greška prilikom spajanja na bazu podataka");
}
?>
<?php include ("include/head.php"); ?>
<body>
<div id="main_container">

<div class="header">
    <div class="logo"><a href="index.php"><img src="images/logo.gif" alt="" title="" border="0" /></a></div>
    
    <div class="right_header">Administrator: <?php echo $_SESSION['SESS_FIRST_NAME'];?> | <a href="odjava.php" class="logout">Odjavi se</a></div>
    <div class="jclock"></div>
    </div>
    
    <div class="main_content">
    
                    <?php include ("include/menu.php");?>                
                    
    <div class="center_content">  
    
           
    <div class="right_content">            
        
       
     <h2>Admin Panel - Unos slika</h2>
     
         <div class="form">
<?php 
error_reporting(0);

$change="";
$abc="";


define ("MAX_SIZE","4096");
function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
}

$errors=0;




$slike = array(file, file1, file2, file3, file4);
  if($_SERVER["REQUEST_METHOD"] == "POST")
{
//	$image =$_FILES["file"]["name"];
//	$uploadedfile = $_FILES['file']['tmp_name'];
$filearray = array();
$filearray1 = array();
$k=0;

  foreach($slike as $slika){ 
$image =$_FILES[$slika]["name"];
$uploadedfile = $_FILES[$slika]['tmp_name'];
	if ($image) 
	{

		$filename = stripslashes($_FILES[$slika]['name']);

  		$extension = getExtension($filename);
		$extension = strtolower($extension);


if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
		{

			$change='<div class="msgdiv">Unknown Image extension </div> ';
			$errors=1;
		}
		else
		{

$size=filesize($_FILES[$slika]['tmp_name']);


if ($size > MAX_SIZE*4096)
{
$change='<div class="msgdiv">Slika je veća od 4096kb!</div> ';
$errors=1;
}


if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES[$slika]['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);

}
else if($extension=="png")
{
$uploadedfile = $_FILES[$slika]['tmp_name'];
$src = imagecreatefrompng($uploadedfile);

}
else 
{
$src = imagecreatefromgif($uploadedfile);
}

echo $scr;

list($width,$height)=getimagesize($uploadedfile);


$newwidth=700;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);


$newwidth1=190;
$newheight1=140;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);


//$filename = "images/". $_FILES['file']['name'];

//$filename1 = "images/small". $_FILES['file']['name'];
$rand = rand(0000000000, 9999999999);
$image_name=(date("dmY")+$k).'_'.$rand.'.'.$extension;
$filename = "../slike/".$image_name;
$filename1 = "../slike/thumbnails/".$image_name;
$filename3 = $image_name;
$filename4 = $image_name;
$id_galerije = $_GET['id_galerije'];

imagejpeg($tmp,$filename,100);

imagejpeg($tmp1,$filename1,100);



$filearray[$k]= $filename3;
$filearray1[$k]= $filename4;
$filearray2[$k]= $id_galerije;
$k++;

// 3. Perform database query
mysql_query("INSERT INTO slike set picture_name='$filename3', picture_name1='$filename4', id_galerije='$id_galerije'");
echo '<br /><img src="../slike/thumbnails/'.$filename4.'"><br />';
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
}}
}
}
// If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors) 
{
	if ($filename3==""){
echo " <table width='400px' align='center' cellspacing='0'>
<tr bgcolor='#E6e6e6' height='26'>
	<td align='center' width='100%' colspan='2'><strong>Potvrda</strong></td>
</tr>
<tr bgcolor='#F6f6f6'>
    <td align='center' style='border-left:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><img src='images/warning.png'></td>
<td align='center' width='80'% style='border-right:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><strong>Slike nisu unešene.</strong></td>
</tr>
</table><br />";
}
else{ 
	echo " <table width='400px' align='center' cellspacing='0'>
<tr bgcolor='#E6e6e6' height='26'>
	<td align='center' width='100%' colspan='2'><strong>Potvrda</strong></td>
</tr>
<tr bgcolor='#F6f6f6'>
    <td align='center' style='border-left:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><img src='images/valid.png'></td>
<td align='center' width='80'% style='border-right:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><strong>Slike uspješno unesene.</strong></td>
</tr>
</table><br />";
}
}
/*If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors) 
{

   // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");
	$change=' <div class="msgdiv">Image Uploaded Successfully!</div>';
}*/


?>
     <div align="center" id="err">
<?php echo $change; ?>  </div>
		    
<form method="post" action="" enctype="multipart/form-data" name="form1">
<?php foreach($slike as $c){ ?>
    <input size="25" name="<?php echo $c?>" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/><br />
    <?php } ?>
Dozvoljen je unos slika veličine do 4 mb! <br />
<input type="submit" id="mybut" value="Unesi slike" name="Submit"/>
</form>
  
<?php 
// 5. Close connection
mysql_close($connection);
?>
         </div>  
      
     
     </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->

    
    <div class="footer"><br />
    
<?php include ("include/footer.php"); ?>
    
    </div>

</div>		
</body>
</html>

Link to comment
Share on other sites

Do you have access to your php.ini or httpd.conf files? you can set the tmp_upload folder there, or you can use something like:

 

ini_set('upload_tmp_dir','folder name');

 

make sure the folder you choose or create has the correct permissions.

 

hope this helps.

 

 

 

 

 

Link to comment
Share on other sites

Do you have access to your php.ini or httpd.conf files? you can set the tmp_upload folder there, or you can use something like:

 

ini_set('upload_tmp_dir','folder name');

 

make sure the folder you choose or create has the correct permissions.

 

hope this helps.

No, when i get with fillezilla only can see public_html folder.

Link to comment
Share on other sites

in that case try my second option:

 

1. create a folder (lets call it TEMP)

2. change permissions: chmod 777 TEMP

3 add ini_set('upload_tmp_dir','TEMP'); at the top of your script (assuming both script and folder are in same directory, otherwise add full path to folder)

 

Hope this helps.

Link to comment
Share on other sites

host is in Croatia and first time working with them. They don't give cpanel, when i need mysql database i must e-mail them to open one for me. when i try to run phpinfo it's get error that is blocked for security reason. Never in my life have problem with hoster until now. This upload script i have for years and work on every host normaly.

Link to comment
Share on other sites

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.