Page 1 of 1

picture wont upload.

Posted: Fri Jun 25, 2010 5:05 am
by aravona
I need to sort out a pre-exisiting file upload for someone and how it looks to me is that most of whats needed is in the file but its just not working.

The following is the PHP section of the file.

Code: Select all

 
<?php
require_once "FCKeditor/fckeditor.php";
if(isset($_REQUEST['btnSubmit'])){
		
		$bool=false;
		$class->begin();

		$prID=$class->getMaximum("prID","ver_pro")+1;
		
		$cID=$_REQUEST['subjects'];
	    $pID=$_REQUEST['links'];
		$mID=1;
		$name=$class->sql_quote($_REQUEST['name']);
		$avail=$class->sql_quote($_REQUEST['avail']);
		$prCode=$class->sql_quote($_REQUEST['prCode']);
		$price=$class->sql_quote($_REQUEST['price']);
		if($_FILES['ImageFile']['name']!=''){
		$image_path=$_FILES['ImageFile']['name'];
	}else{
		$image_path="default1.gif";
	}
		$description=$class->sql_quote($_REQUEST['description']);
		$stitle=$class->sql_quote($_REQUEST['stitle']);
	    $sdescription=$class->sql_quote($_REQUEST['sdescription']);
	    $skeywords=$class->sql_quote($_REQUEST['skeywords']);
		
		$active=1;
		
		
		$otherpro = $_POST['otherproduct'];
		
		$temp_gallery ="../upload/tmp/";
		$target_dir ="../upload/";
		
		$query="INSERT INTO ver_pro(prID,cID,pID,mID,name,avail,prCode,price,image_path,description,active,stitle,sdescription,skeywords) 	
							VALUES('".$prID."','".$cID."','".$pID."','".$mID."','".$name."','".$avail."','".$prCode."','".$price."','".$image_path."','".$description."','".$active."','".$stitle."','".$sdescription."','".$skeywords."')";
			/*echo $query;
			die();*/
			if($class->executeQuery($query)==false) $bool=true;
	
			if($bool==true){
				$class->rollback();
				header("Location: index.php?cmd=11&error=0");
				exit;
			}else{
				$class->commit();
				
				if($_FILES['ImageFile']['name']!=''){
			    $file1=$temp_gallery.$ID.$_FILES[ImageFile][name];		
		        move_uploaded_file ($_FILES[ImageFile][tmp_name],$file1);
				include_once("resizeimage.inc.php");
				
				$rimg=new RESIZEIMAGE($temp_gallery.basename($file1));
				echo $rimg->error();
				$rimg->resize(300,240,$target_dir."1_".basename($file1));
				$filename = $target_dir."2_".basename($file1);
				copy($file1, $filename);			
			
						//$rimg->resize($target_dir."/3_".basename($file));  
						@unlink($temp_gallery.basename($file1)); 
						$rimg->close();
    	
		}
				
				$sSQL = "INSERT INTO ver_otherpro (prCode, prOther) values "; 
		 $bAppened = FALSE; 

				foreach($otherpro as $other) 
					   { 
					    if ($bAppened) 
         				$sSQL .= ','; 
     					 else 
						$bAppened = TRUE;
						  $sSQL .= "('".$prCode."','".$other."')"; 
					   }
					   
			if($class->executeQuery($sSQL)==false) $bool=true;
			
			if($bool==true){
				$class->rollback();
				
				
			}else{
				$class->commit();
				
						}
				
				
			header("Location: index.php?cmd=11&err=1");
				exit;
			}//end of if
	}	
	
	
?>
The file works on self, 'index.php?cmd=10' is the page which loads the form. However it works as in the fact the file path gets inserted, but then no image gets on the server, and I've double checked that it is allowed to upload... Now I never was any good at uploading pictures at uni though php, but I got there in the end, however... we had to save it into the database and I need this to go into a folder on a server.

Basically I'm not sure how to go about getting the code in the above file working in the same way the files in the .zip from the image thread work.

Any help I'd really appriciate!

Aravona

Re: picture wont upload.

Posted: Fri Jun 25, 2010 1:17 pm
by internet-solution
aravona wrote: and I've double checked that it is allowed to upload...
Whats the CHMOD of the server folder?

Re: picture wont upload.

Posted: Mon Jun 28, 2010 3:05 am
by aravona
No clue, fluent doesn't tend to give out information.

Re: picture wont upload.

Posted: Mon Jun 28, 2010 3:56 am
by cpetercarter
When you hit a problem like this, it is vital to turn on error messaging, so that you (and we) can see what php is telling you is wrong.

The problem may be in this bit:

Code: Select all

$file1=$temp_gallery.$ID.$_FILES[ImageFile][name];         
                        move_uploaded_file ($_FILES[ImageFile][tmp_name],$file1);
I cannot see where $ID is defined.
Also, although you can often get away with not quoting string variables in offsets, it is best to do so. (so, $_FILES['ImageFile']['name']).

However, as aravona suggests, it is possible that the ../upload/tmp/ directory is not writable by php. You don't need to ask your web host. You can find out for yourself. Navigate to the directory in an ftp client like FileZilla, highlight the directory and right-click. Choose "properties" or "file attributes" to see the directory permissions. They need to be set at 0777; or the directory needs to be owned by the web server with permissions 0755.

Or you can test whether the directory is writable by adding this immediately after the line where you define $temp_gallery:

Code: Select all

if (!is_writable($temp_gallery)) die ("Help! I cannot write things into the temp_gallery");

Re: picture wont upload.

Posted: Mon Jun 28, 2010 4:23 am
by aravona
I've already set everything from the upload folder and all sub-folders to be set to 777. That was one of the first things that I checked.

I have no clue where the Id is being set either, I will try taking it out and see what happens. However the folder is definately writable. This code is used on another website as well, and they say they have no problems whatsoever.

Tried removing the ID... nothing same problem as before... the file path gets set fine but theres no image uploaded.

EDIT: Ok, adding that in I just get 'Help! I cannot write things into the temp_gallery' So the problem is there I guess?

EDIT 2: Oooook.... It worked for a minute or two there now suddenly stopped again >.>