Jump to content

Joomla pains oh god help me please


Ruzzas

Recommended Posts

I am trying to make a file upload to a directory and then just simply upload it to a remote connection. The problem is, Well... I honestly don't know...

 

I'm good with PHP overall but when it comes to Joomla, I turn into a curious monkey.

 

function UploadToRemote($tempFile,$targetPath,$targetFile){
        global $jlistConfig;
	    ignore_user_abort(true);
	    set_time_limit(3600);

	    $conn = ftp_connect($jlistConfig['ftp.address']) or die('FTP Connection failed');
	    $login = ftp_login($conn,$jlistConfig['ftp.username'],$jlistConfig['ftp.password']) or die('FTP Login failed');		    

	    if(!ftp_chdir($conn,$targetPath)){
            if(ftp_mkdir($conn,$targetPath)){
			        ftp_chdir($conn,$targetPath);
		      }else{
	    		    $success = 0;
	    	  }
	        if(ftp_put($conn,$targetFile,$tempFile,FTP_BINARY)){
	    	      $success = 1;
	        }else{
	    	      die('Failed uploading the file...');
    		    }
    		}
    		ftp_close($conn);
    		return $success;
    }           		
	//datei upload bearbeiten
    if($file_upload['tmp_name']!=''){
        // replace special chars in filename
        $filename_new = checkFileName($file_upload['name']);
        $upload_dir = '/'.$jlistConfig['files.uploaddir'].'/'.$mark_catdir.'/';
        $ftp_dir = '/'.$jlistConfig['ftp.folder'].'/'.$mark_catdir.'/';
        $dir_and_filename = str_replace('/'.$jlistConfig['files.uploaddir'].'/', '', $upload_dir.$filename_new);
			$target_path = JPATH_SITE.$upload_dir.$filename_new;
        // upload only when the file not exist in the directory
        if(!is_file($target_path)){
	        if(@move_uploaded_file($file_upload['tmp_name'], $target_path)){
	            $Upload = UploadToRemote($file_upload['tmp_name'], $jlistConfig['ftp.folder'].'/'.$mark_catdir.'/', $jlistConfig['ftp.folder'].'/'.$mark_catdir.'/'.$filename_new) or die('Failed to upload...');
                // get filesize
               	$size = fsize($target_path);
               	// get filedate
            		$date_added = JHTML::_('date', 'now', '%Y-%m-%d %H:%M:%S' );
				      $url_download = basename($target_path);
                $url_download = utf8_encode($url_download);
				      // auto publish ?
                if($jlistConfig['upload.auto.publish']){
                    $publish = 1;
                    setAUPPointsUploads($submitted_by, $filetitle);
                    $set_aup_points = 0;
                }else{
                    $set_aup_points = 1;
                    $publish = 0;
                }
                $file_extension = strtolower(substr(strrchr($url_download,"."),1));
                $filepfad = JPATH_SITE.'/images/jdownloads/fileimages/'.$file_extension.'.png';
                if(file_exists(JPATH_SITE.'/images/jdownloads/fileimages/'.$file_extension.'.png')){
                    $filepic = $file_extension.'.png';
                }else{
                    $filepic = $jlistConfig['file.pic.default.filename'];
                }                    
                $database->setQuery("INSERT INTO #__jdownloads_files (`file_id`, `file_title`, `file_alias`,`description`, `description_long`, `file_pic`, `thumbnail`, `thumbnail2`, `thumbnail3`, `price`, `release`, `language`, `system`, `license`, `url_license`, `size`, `date_added`, `file_date`, `url_download`, `url_home`, `author`, `url_author`, `created_by`, `created_mail`, `modified_by`, `modified_date`, `submitted_by`, `set_aup_points`, `downloads`, `cat_id`, `ordering`, `published`, `checked_out`, `checked_out_time`)
                                                                     VALUES (NULL, '$filetitle', '$file_alias', '$description', '$description_long', '$filepic', '$thumbnail', '$thumbnail2', '$thumbnail3', '$price', '$version', '$language_sel', '$system_sel', '$license_sel', '', '$size', '$date_added', '', '$url_download', '$author_url', '$author', '', '$name', '$mail', '', '0000-00-00 00:00:00', '$submitted_by', '$set_aup_points', '0', '$catlist_sel', '0', '$publish', '0', '0000-00-00 00:00:00')");
	   	   		  if(!$database->query()){
					        // fehler beim erstellen in DB	
					        echo $database->stderr();
					        exit;
				      }					 
                // alles OK!
                if(!$msg){
                        $msg = '<div>'.$upload_ok_pic.'<font color="green"> '
                            .JText::_('JLIST_FRONTEND_UPLOAD_OK').
                            '</font><br /> </div>';
                        $html_form = str_replace('{form}', '{msg}{form}', $html_form);
                        // send email wenn aktiviert
                        if($jlistConfig['send.mailto.option.upload']){
                            sendMailUploads($name, $mail, $url_download, $filetitle, $description);   
                        }    
                    }
                }else{
				      // fehler beim verschieben
				      $msg = '<div>'.$upload_stop_pic.'<font color="red"> '
			   		      .JText::_('JLIST_FRONTEND_UPLOAD_ERROR_MOVE_FILE').
			   		      '</font><br /> </div>';
                $html_form = str_replace('{form}', '{msg}{form}', $html_form);	
            }
        }else{
            // file exist with the same name
            $msg = '<div>'.$upload_stop_pic.'<font color="red"> '
                .JText::_('JLIST_FRONTEND_UPLOAD_ERROR_FILE_EXISTS').
                '</font><br /> </div>';
            $html_form = str_replace('{form}', '{msg}{form}', $html_form);    
        } 
    }

 

Please help me!

Link to comment
Share on other sites

How do you expect us to know? We have even less insight than you do. What happens when you run the code, blank page? Errors? Have you debugged the code to find the breaking point? etc.

 

No errors, I'm having trouble spotting the errors because of such a slow website.

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.