regoch Posted June 2, 2011 Share Posted June 2, 2011 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 https://forums.phpfreaks.com/topic/238212-upload-image/ Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 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 https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224120 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 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 https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224124 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 where to put ini_set('upload_tmp_dir','folder name'); in my code? Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224127 Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 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 https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224130 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 Not working. Only get black image in "slike/thumbnail" folder, in "slike" folder nothing. slike menas images in croatian! Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224136 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 I try to search new script on net but none have temp folder specified. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224228 Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 several things to try here: http://www.bala-krishna.com/how-to-fix-missing-a-temporary-folder-error-in-wordpress/ Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224244 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 I can't get to php.ini, I think i will tell him to move to another hosting company. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224251 Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 you may not have a php.ini file yet. on the page I sent you there are also instructions for creating your own php.ini if the host supports custom php.ini. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224252 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 Who is the web host and what kind of control panel is there? Cpanel? Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224254 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 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 https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224256 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 Definitely get a different host. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224257 Share on other sites More sharing options...
WebStyles Posted June 2, 2011 Share Posted June 2, 2011 man, that's kind of funny. I would change hosting account to a decent one. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224258 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 <?php upload_tmp_dir = "/home/homefolder/public_html/tmp/"; ?> I create php.ini put this code in but it is still same. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224261 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 You are going to spend more time trying to get this host working than you would setting up a whole new ecommerce site on another host. You'd probably even get your first sale before you got that host working. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224267 Share on other sites More sharing options...
regoch Posted June 2, 2011 Author Share Posted June 2, 2011 i give up. spent to much time for this. tell friend to change host. i search web i find there is posibility to add flickr gallery to the site. Link to comment https://forums.phpfreaks.com/topic/238212-upload-image/#findComment-1224270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.